MisterniceGuy
MisterniceGuy

Reputation: 1796

How can i create a certain format in moment?

i am trying to change the output of a moment format to look like the standard output in morgan except that it uses my Timezone. my morgan time part looks like this

Wed, 10 Apr 2019 05:02:31 GMT

i would like it to be the same except to display time in PST

Upvotes: 1

Views: 66

Answers (3)

MisterniceGuy
MisterniceGuy

Reputation: 1796

var moment = require('moment-timezone');
var myDate = moment().tz("America/Los_Angeles").format('ddd, DD MMM YYYY HH:mm:ss z');

the above actually creates the exact thing i was looking for

Upvotes: 0

LionKing
LionKing

Reputation: 536

You can check the Moment Js document says you can use moment.format() to get the format you want it, and for your case it will be the one below:

moment().format('dddd Do MMM YYYY h:mm:ss a');

Upvotes: 0

Trevor Johnson
Trevor Johnson

Reputation: 936

You can use moment to create a specific format like this:

moment().format("dddd, MMMM Do YYYY, h:mm:ss a");

That will output the current time of the server/machine you are on into the format you are looking for, except for the timezone part. There is an additional moment-timezone package to use for timezones. This may be a good starting point for you on the timezone part based on the docs:

moment().tz('Etc/GMT+1').format('YYYY-MM-DD HH:mm ZZ')

https://momentjs.com/timezone/docs/

Upvotes: 1

Related Questions