Skip to content

Instantly share code, notes, and snippets.

@yudapc
Created September 20, 2018 14:55
Show Gist options
  • Save yudapc/97c371bf1ffef7d9b474a90215563db4 to your computer and use it in GitHub Desktop.
Save yudapc/97c371bf1ffef7d9b474a90215563db4 to your computer and use it in GitHub Desktop.
moment js
Cheat moment:
http://momentjs.com/
http://momentjs.com/timezone/
moment = require('moment-timezone')
get current time AM/PM
moment().format('hh:mm A')
// 09:54 PM
get current time 24
moment().format('HH:mm')
// 21:54
get client current timezone:
moment.tz.guess();
// Asia/Jakarta
iso8601:
moment('2018-09-20 08:00 AM').toISOString()
// '2018-09-20T01:00:00.000Z'
format time from AM/PM to 24:
moment('12:00 AM', 'hh:mm A').format('HH:mm')
// 00:00
convert time to another timezone:
moment('2018-09-20T04:00:00.000Z').tz('Asia/Makassar').format('YYYY-MM-DD HH:mm')
// '2018-09-20 12:00'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment