0

I'm trying to convert current time in hours and getting an error called DateTime not defined help from Anyone?

import { LightningElement,api, track,wire } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';

export default class GetTimeinHours extends NavigationMixin(LightningElement) {

 handleSubmit(event){
 
            const fields = event.detail.fields;
            let rightNow = new Date();
            this.rolloverFlag = true;
            // Adjust for the user's time zone
            rightNow.setMinutes(
            new Date().getMinutes() - new Date().getTimezoneOffset()
            );
            // Return the date in "YYYY-MM-DD" format
            let yyyyMmDd = rightNow.toISOString().slice(0,10);
            
            const CurrentTimeinHours = Datetime.now().hour();---------------> This line Causing an error, I'm trying converting current time in hours
            console.log('CurrentTimeinHours----->'+CurrentTimeinHours);

            if(fields.ET_Effective_Date__c === yyyyMmDd || CurrentTimeinHours < 11){

                fields.ET_Urgent_Flag__c = true;
            }
            else{
                console.log('Flag FALSE');
                fields.ET_Urgent_Flag__c = false;

            }
 }

}

Regards, Chan

3
  • To get the current hour value try this: const dateObj = new Date(); const currentHours = dateObj.getHours(); console.log('currentHours ::' + currentHours); Commented Dec 8, 2023 at 5:20
  • I am slightly confused. The Date value you get with "rightNow" is already in the browser's time zone, which will normally be the user time zone (depending on setup of course).
    – Phil W
    Commented Dec 8, 2023 at 7:26
  • As the error suggests, there is no Datetime in Javascript. Date contains functionality for datetimes as well.
    – Derek F
    Commented Jan 8 at 13:48

0

You must log in to answer this question.

Browse other questions tagged .