Skip to content

Instantly share code, notes, and snippets.

@armedi
Last active January 3, 2022 07:35
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 armedi/6080174a4e7e3e6fc2bf301297907fd4 to your computer and use it in GitHub Desktop.
Save armedi/6080174a4e7e3e6fc2bf301297907fd4 to your computer and use it in GitHub Desktop.
Menggunakan library masa untuk memformat tanggal ke bahasa Indonesia
import { masa } from 'masa';
masa(new Date('2020-08-17')).format('[hari] dddd, [tanggal] D MMMM YYYY');
// hari Senin, tanggal 17 Agustus 2020
@willnode
Copy link

willnode commented Jan 2, 2022

Alternatif tanpa library

const formatTglID = (tgl) => new Date(tgl).toLocaleString('id-ID', {
    timeZone: 'Asia/Jakarta',
    weekday: 'long',
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    timeZoneName: 'short',
}).replace(/\./g, ':');

console.log(formatTglID("2022-01-01T12:25:15Z")) // Sabtu, 01 Januari 2022 19:25:15 WIB

@armedi
Copy link
Author

armedi commented Jan 3, 2022

thanks @willnode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment