@oluwanifemi/date-formatt 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/index.js +61 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# date-formatt
|
package/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const { module } = require("browserify/lib/builtins")
|
|
2
|
+
|
|
3
|
+
const date = new Date()
|
|
4
|
+
// console.log(date) --> this returns a date in the ISO 8601 format,
|
|
5
|
+
// commonly used in databases, APIs and JavaScript
|
|
6
|
+
|
|
7
|
+
// e.g "2026-03-09T11:42:13.260Z"
|
|
8
|
+
// Date portion --> "YYYY-MM-DD" --> "2026-03-09"
|
|
9
|
+
// Time portion --> "HH:MM:SS.milliseconds" --> "11:42:13.260Z"
|
|
10
|
+
// T --> Indicator for time portion starting point
|
|
11
|
+
// Z --> "Zulu Time"/"Coordinated Universal Time (UTC)"
|
|
12
|
+
|
|
13
|
+
const d = new Date("October 13, 2014 11:13:00")
|
|
14
|
+
// console.log(d) --> this also returns the date in ISO 8601 format
|
|
15
|
+
// C:\Users\FullstackCreator\Documents\Programming\date-formatt
|
|
16
|
+
|
|
17
|
+
function iso(date) {
|
|
18
|
+
return date.toISOString().split("T")[0]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function short(date) {
|
|
22
|
+
return date.toLocaleDateString("en", {
|
|
23
|
+
day: "numeric",
|
|
24
|
+
month: "short",
|
|
25
|
+
year: "numeric"
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function long(date) {
|
|
30
|
+
return date.toLocaleDateString("en", {
|
|
31
|
+
weekday: "long",
|
|
32
|
+
month: "long",
|
|
33
|
+
day: "numeric",
|
|
34
|
+
year: "numeric"
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function dateTime(date) {
|
|
39
|
+
return date.toLocaleString("en", {
|
|
40
|
+
day: "numeric",
|
|
41
|
+
month: "short",
|
|
42
|
+
year: "numeric",
|
|
43
|
+
hour: "numeric",
|
|
44
|
+
minute: "2-digit"
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function time(date) {
|
|
49
|
+
return date.toLocaleTimeString("en", {
|
|
50
|
+
hour: "numeric",
|
|
51
|
+
minute: "2-digit"
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = {
|
|
56
|
+
iso,
|
|
57
|
+
short,
|
|
58
|
+
long,
|
|
59
|
+
dateTime,
|
|
60
|
+
time
|
|
61
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oluwanifemi/date-formatt",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A utility package that allows you to get dates in desired formats",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/KazeemOluwanifemi/date-formatt.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"date",
|
|
15
|
+
"format"
|
|
16
|
+
],
|
|
17
|
+
"author": "Kazeem Oluwanifemi",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/KazeemOluwanifemi/date-formatt/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/KazeemOluwanifemi/date-formatt#readme"
|
|
23
|
+
}
|