preloader
學習

Datetime Format With YYYY-MM-DD HH:mm:ss in Nodejs V18 and After | 在 nodejs v18以上版本是用內建函式製作日期時間格式 YYYY-MM-DD HH:mm:ss

Using nodejs v18+ built-in datetime formatter, code are below

new Intl.DateimeFormat('fr', {
  timezone: 'Asia/Taipei',
  year: 'numeric',
  month: '2-digit',
  day: '2-digit',
  hour: '2-digit',
  minute: '2-digit',
  second: '2-digit',
}).format(new Date('2024-10-24T10:00:03Z'))

print 2024-10-24 18:00:03   It can be used to server and serverless environment such as GCP cloudfunction, …etc.