Bryl
Bryl

Reputation: 436

React Native - Customize date format using Moment.js

I am using moment.js to get the current date, however I am having a problem about the date formatting and I don't have any idea on how to customize it since I am just new using it.

By the way I used this.

moment().format('LLLL');

My expected output is:

Mmmm-dd-yyyy hh:mmAM/PM (Timezone) or just like Sep-19-2020 3:00AM (GMT +8)

Is the any other way to achieve this?

Upvotes: 2

Views: 3937

Answers (1)

Göksel Pırnal
Göksel Pırnal

Reputation: 108

moment().locale('tr').format("MMM-DD-yyyy h:mA [(GMT] Z[)]")
moment().locale('en_US').format("MMM-DD-yyyy h:mA [(GMT] Z[)]")

If you want to use locale in React Native.

instead

import moment from 'moment'

you should use this

import 'moment/min/moment-with-locales'
moment.locale('tr');
moment().format("MMM-DD-yyyy h:mA [(GMT] Z[)]");
  • The things you write in square brackets are written directly. that is, they are escape characters. 

Upvotes: 5

Related Questions