Link to home
Create AccountLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How do I set the correct time in this code?

I'm in a Nodejs application, I'm putting to together the data that's going to be displayed by "formit.js."

The code looks like this:

this.showActivityForm = (companyId, proposalId, type) => {
      const model = objectModels[type];
      const fc = model.singular.substring(0, 1);
      const config = {
        title: `Add a${
          fc === 'a' || fc === 'e' || fc === 'i' || fc === 'o' || fc === 'u'
            ? 'n'
            : ''
        } ${ucwords(model.singular)}`,
        directionsText: `Complete the form below to add a${
          fc === 'a' || fc === 'e' || fc === 'i' || fc === 'o' || fc === 'u'
            ? 'n'
            : ''
        } new ${model.singular}.`,
        fields: model.fields,
        onShow(e) {
          // add in the additional events and plugins
          // add in datetime support
          e.$el.find('input.field-datetime').daterangepicker({
            singleDatePicker: true,
            timePicker: true,
            showDropdowns: true,
            minDate: moment()
              .subtract(25, 'years')
              .startOf('hour'),
            maxDate: moment()
              .add(25, 'years')
              .endOf('hour'),
            locale: {
             [b] format: 'MM/DD/YYYY hh:mm A'[/b]
            }
          });
        },
        ajax: {
          path: '/companies/add-activity',
          params: {
            company: companyId,
            proposal: proposalId,
            type
          },
          onComplete(resp, e) {
            if (resp.error) {
              e.addMsg(resp.msg);
              return false;
            }

            const companyIdDetails =
              companyId === 'bulk' ? resp.data.id : companyId;

            $(window).trigger('open-company-details', [
              companyIdDetails,
              typeof route !== 'undefined' ? route : '/companies/',
              'history'
            ]);
            return true;
          }
        }
      };

      // show the form
      // eslint-disable-next-line no-use-before-define
      formIt.show(config);
    };

Open in new window


The piece that I have in bold is my challenge. The date is correct, but the time needs to be the local time. Right now, it's defaulting to 12:00 AM.

How do I fix that?
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Bruce Gust

ASKER

You know what, David? Then I'm going to eliminate the time portion.

Thanks!
To my opinion it is better to manage the time in a seperate field.

There are some plugins that have date and the time
https://eonasdan.github.io/bootstrap-datetimepicker/ 
lenamtl!

You know what? This problem is happening elsewhere as well. Let me put together another question and give you the chance to weigh in on it.

Stand by...

Here: https://www.experts-exchange.com/questions/29182102/How-can-I-get-this-date-to-display-correctly.html#questionAdd 
Avatar of azeem ali
azeem ali

Actually I have checked the above section there is no mention data main thing to want to exact data also current date using javascript JavaScript Date Format mm/dd/yyyy 
var date_format = new Date(); 
document.write(innerHTML = date_format.getMonth()+'/'+ date_format.getDate()+'/'+date_format.getFullYear());

Open in new window