~sirn/fanboi2

ref: a68873a108d20a6a49a1b6caf374bfb2cf6a94fe fanboi2/assets/app/javascripts/utils/formatters.ts -rw-r--r-- 625 bytes
a68873a1Kridsada Thanabulpong Coding style cleanups and setup pre-commit hooks (#42) 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const monthNames = [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec",
];

export let formatDate = (date: Date): string => {
    let yyyy = date.getFullYear();
    let mmm = monthNames[date.getMonth()];
    let dd = `00${date.getDate()}`.slice(-2);
    let hh = `00${date.getHours()}`.slice(-2);
    let nn = `00${date.getMinutes()}`.slice(-2);
    let ss = `00${date.getSeconds()}`.slice(-2);
    let dateFormatted = `${mmm} ${dd}, ${yyyy}`;
    let timeFormatted = `${hh}:${nn}:${ss}`;

    return `${dateFormatted} at ${timeFormatted}`;
};