-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateFormat.js
More file actions
58 lines (45 loc) · 1.96 KB
/
DateFormat.js
File metadata and controls
58 lines (45 loc) · 1.96 KB
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
const DateFormat = {
getDayOfWeek: function(date) {
var year = date.getYear();
var month = date.getMonth();
var day = date.getDay();
var t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
var tempYear = year;
tempYear -= ((month < 3) ? 1 : 0);
var dow = Math.floor(tempYear + tempYear / 4 - tempYear/100 + tempYear/400 + t[month-1] + day) % 7;
var dayOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
return dayOfWeek[dow];
},
getMonth: function(date) {
var month = date.getMonth()-1;
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
return months[month];
},
globalPrintingDate: function(date) {
return DateFormat.getDayOfWeek(date) + " " + date.getDay() + " " + DateFormat.getMonth(date) + " " + date.getYear();
},
globalPrintingTime: function(date) {
var minute = date.getMinute() + "";
if (minute.length == 1) minute = "0" + minute;
var second = date.getSecond() + "";
if (second.length == 1) second = "0" + second;
return date.getHour() + ":" + minute + ":" + second;
},
americanPrintingDate: function(date) {
return DateFormat.getDayOfWeek(date) + " " + DateFormat.getMonth(date) + " " + date.getDay()+ " " + date.getYear();
},
americanPrintingTime: function(date) {
var hourIn = date.getHour();
var pm = false;
var hour = hourIn % 12;
if (hour == 0) hour = 12;
if (hourIn >= 12) pm = true;
var timeType = pm ? "PM" : "AM";
var minute = date.getMinute() + "";
if (minute.length == 1) minute = "0" + minute;
var second = date.getSecond() + "";
if (second.length == 1) second = "0" + second;
return hour + ":" + minute + ":" + second + " " + timeType;
}
}
module.exports = DateFormat;