-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtime.js
44 lines (42 loc) · 1.04 KB
/
time.js
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
/**
* getTimeInNorwegian
* Returns a date in norwegian time
*
* @return date in norwegian time
* */
function getTimeInNorwegian() {
let norTime = new Date().toLocaleString("no-no", {timeZone: "Europe/Oslo"});
return new Date(norTime);
}
/**
*
* pad
* Pads the numbers
*
* @param number
* @return number padded
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
* */
function pad(number) {
if (number < 10) {
return '0' + number;
}
return number;
}
/**
*
* toNORString
*
* Converts the date as it is time, it's like toISOString
* only, it just converts the time to string without changing the time :)
*
* Inspired by:
* @Link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
* */
Date.prototype.toNORString = function () {
return this.getFullYear() +
'-' + pad((this.getMonth()) + 1) +
'-' + pad(this.getDate()) +
'T' + pad(this.getHours()) +
':' + pad(this.getMinutes());
};