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
const dateObj = new Date(); const currentHours = dateObj.getHours(); console.log('currentHours ::' + currentHours);
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).Datetime
in Javascript.Date
contains functionality for datetimes as well.