Skip to content

Format วันที่ พ.ศ. #10

@rootEnginear

Description

@rootEnginear
const date_formatter = new Intl.DateTimeFormat('th-TH', {
  dateStyle: 'short'
});
const formatDate = (date: Date) => date_formatter.format(date);

formatDate( new Date(2022,9,31) ) // 31/10/65

เวลากรอก กรอก ค.ศ. ตามปกติ แล้วเดี๋ยว Intl จะ format เป็น พ.ศ. ให้เลย

dateStyle แบบต่างๆ

dateStyle ผลลัพธ์
'short' '31/10/65'
'medium' '31 ต.ค. 2565'
'long' '31 ตุลาคม 2565'
'full' 'วันจันทร์ที่ 31 ตุลาคม พ.ศ. 2565'

Ref

DateTimeFormat() - MDN

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions