user1892775
user1892775

Reputation: 2111

Date formatting using moment

I was playing with moment library in node and was trying to format dates:

moment().tz(timezone).format('dddd')

This formatting gives me the current day of the week like 'Tuesday'

Now, I want to format like: 'Tuesday May 2, 2017'

What will be the best way to format it this way using moment?

Upvotes: 1

Views: 88

Answers (1)

VincenzoC
VincenzoC

Reputation: 31482

You can simply use moment format(), in your case you have to use 'dddd MMMM D, YYYY' where:

  • dddd stands for the day of the week name
  • MMMM stands for month's name
  • D stands for the day of the month
  • YYYY stands for the four digit year

Here a working sample:

var timezone = 'Europe/Rome';
console.log(moment().tz(timezone).format('dddd MMMM D, YYYY'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.13/moment-timezone-with-data-2012-2022.min.js"></script>

Upvotes: 1

Related Questions