Skip to content

Instantly share code, notes, and snippets.

@olegchursin
Created July 10, 2022 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegchursin/382f863b7063dcd1117985e7439bec6d to your computer and use it in GitHub Desktop.
Save olegchursin/382f863b7063dcd1117985e7439bec6d to your computer and use it in GitHub Desktop.
Get datetime default value for input field.
export const getDatetimeDefaultValue = (timestamp: Date | string): string => {
let ts = new Date();
if (timestamp) {
ts = new Date(timestamp);
}
ts.setMinutes(ts.getMinutes() - ts.getTimezoneOffset());
ts.setMilliseconds(null);
ts.setSeconds(null);
return ts.toISOString().slice(0, -1);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment