-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime-dates.ts
90 lines (81 loc) · 2.12 KB
/
time-dates.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
export function todaysDate(): string {
const date = new Date();
const dayOfWeek: string = dayOfTheWeekShort();
const month: string = writtenShortMonth();
const day: number = date.getDate();
const year: number = date.getFullYear();
const fullDate: string = `${dayOfWeek} ${month} ${day}, ${year}`;
return fullDate;
}
export function currentTime(): string {
const date = new Date();
const hours = amPmTime();
const mins = date.getMinutes();
const time = `${hours[0]}:${mins} ${hours[1]}`;
return time;
}
export function currentDate(): string {
const d = new Date();
let month = addZero(d.getMonth() + 1);
let day = addZero(d.getDate());
let currDate = `**** ${d.getFullYear()}-${month}-${day}`;
return currDate;
}
function addZero(num: number) {
if (num.toString().length < 2)
// Integer of less than two digits
return "0" + num; // Prepend a zero!
return num.toString(); // return string for consistency
}
function amPmTime(): any {
const date = new Date();
const hours = date.getHours() > 11 ? date.getHours() - 12 : date.getHours();
const amPm: string = date.getHours() > 11 ? "PM" : "AM";
return [hours, amPm];
}
function writtenFullMonth() {
const date = new Date();
let month = [];
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
return month[date.getMonth()];
}
function writtenShortMonth(): string {
const date = new Date();
let month = [];
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "April";
month[4] = "May";
month[5] = "Jun";
month[6] = "July";
month[7] = "Aug";
month[8] = "Sept";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
return month[date.getMonth()];
}
function dayOfTheWeekShort(): string {
const date = new Date();
let day = [];
day[0] = "Sun";
day[1] = "Mon";
day[2] = "Tue";
day[3] = "Wed";
day[4] = "Thurs";
day[5] = "Fri";
day[6] = "Sat";
return day[date.getDay()];
}