Skip to content

Instantly share code, notes, and snippets.

@icesernia
Created March 8, 2021 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icesernia/6ee8ce4fc4c7e0f25ab4f37dc7a7664f to your computer and use it in GitHub Desktop.
Save icesernia/6ee8ce4fc4c7e0f25ab4f37dc7a7664f to your computer and use it in GitHub Desktop.
let date = new Date();
let options = { weekday: 'long', year: 'numeric', month: 'short', day: 'numeric', timeZone: 'Asia/Bangkok' }
console.log(new Intl.DateTimeFormat('en-US', options).format(date)); // expected output: Saturday, Feb 20, 2021
console.log(new Intl.DateTimeFormat('th-TH', options).format(date)); // expected output: วันเสาร์ที่ 20 ก.พ. 2564
console.log(new Intl.DateTimeFormat('th-TH-u-nu-thai', options).format(date)); // expected output: วันเสาร์ที่ ๒๐ ก.พ. ๒๕๖๔
let options2 = { hour: '2-digit', minute: '2-digit' }
console.log(new Intl.DateTimeFormat('th-TH', options2).format(date)); // expected output: 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment