Skip to content

Instantly share code, notes, and snippets.

@Gummiees
Created October 29, 2020 09:37
Show Gist options
  • Save Gummiees/2e1a20c5d793e006b336962805f9cf82 to your computer and use it in GitHub Desktop.
Save Gummiees/2e1a20c5d793e006b336962805f9cf82 to your computer and use it in GitHub Desktop.
Removes the date UTC offset with moment.js
/** Removes the current UTC offset. */
public removeUtcOffset(utcDate: any): Date {
let date: Date;
if (utcDate instanceof Date) {
date = utcDate;
} else {
date = moment(utcDate, this.localGlobalService.getDashDateMomentFormat()).toDate();
}
const noOffsetDate: Date = moment(date).utc().subtract(date.getTimezoneOffset(), 'm').toDate();
return noOffsetDate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment