Skip to content

Format date? #21

Closed Answered by AbhyudayaSharma
paulywill asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @paulywill. The date is returned as a strict ISO8601 string and can be passed to a Date constructor. You can then use Intl.DateTimeFormat with that date to format it to your liking.

const date = new Date(gitInfo.commit.date);
const options = {
  year: 'numeric', month: 'numeric', day: 'numeric',
  hour: 'numeric', minute: 'numeric', second: 'numeric',
  hour12: false,
  timeZone: 'America/Los_Angeles'
};
console.log(new Intl.DateTimeFormat('en-US', options).format(date))

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by paulywill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #18 on January 03, 2022 05:53.