Avatar of Bruce Gust
Bruce Gust
Flag 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?
Node.jsJavaScript

Avatar of undefined
Last Comment
azeem ali

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
David Johnson, CD

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bruce Gust

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

Thanks!
lenamtl

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/ 
Bruce Gust

ASKER
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 
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
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