This repository has been archived by the owner on May 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (63 loc) · 2.3 KB
/
index.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
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
/**
* Contains example codes for nepali-date package.
*/
import NepaliDate from 'nepali-datetime';
import dateConverter from 'nepali-datetime/dateConverter';
/**
* Initialization
*/
// Without any parameters:
const now = new NepaliDate();
console.log(now.toString()); // 2080-03-27 18:48:28.266
// Date string parameter
const date1 = new NepaliDate('2079-02-15 14:00');
console.log(date1.toString()); // 2079-02-15 14:00
// Unix timestamp
const date2 = new NepaliDate(1654210800000);
console.log(date2.toString()); // 2079-02-20 04:45:00
// Date object
const dateObject = new Date();
const date3 = new NepaliDate(dateObject);
console.log(date3.toString()); // 2080-03-27 18:51:08.968
// NepaliDate object
const date4 = new NepaliDate(date3);
console.log(date3.toString()); // 2080-03-27 18:51:08.968
// Date and time parameters
const date5 = new NepaliDate(2079, 2, 15, 10, 30);
console.log(date5.toString()); // 2079-02-15 10:30:00
// Parse Nepali date string
const date6 = new NepaliDate('Baisakh 18, 2080', 'MMMM D, YYYY')
console.log(date6.toString()) // Outputs: "2080-01-18 00:00:00"
/**
* Methods
*/
// const date1 = new NepaliDate('2079-02-15 14:00');
console.log(date1.getDateObject()); // 2022-05-29T08:15:00.000Z
console.log(date1.getTime()); // 1653812100000
console.log(date1.getYear()); // 2079
console.log(date1.getEnglishYear()); // 2022
console.log(date1.getMonth()); // 1
console.log(date1.getEnglishMonth()); // 4
console.log(date1.getDate()); // 15
console.log(date1.getEnglishDate()); // 30
console.log(date1.getDay()); // 0
console.log(date1.getHours()); // 14
console.log(date1.getMinutes()); // 0
console.log(date1.getSeconds()); // 0
console.log(date1.getMilliseconds()); // 0
/**
* Formatting
*/
// const date1 = new NepaliDate('2079-02-15 14:00');
console.log(date1.format('YYYY')); // 2079
console.log(date1.format('YYYY-MM-DD HH:mm:ss')); // 2079-02-15 14:00:00
console.log(date1.format('"H"ello YYYY-MM-DD Worl"d"')); // Hello 2079-02-15 World
/**
* Date Converter
*/
// english to nepali date conversion
const [npYear, npMonth, npDay] = dateConverter.englishToNepali(2023, 5, 27);
console.log(npYear, npMonth, npDay) // 2080 2, 12
// nepali to english date conversion
const [enYear, enMonth, enDay] = dateConverter.nepaliToEnglish(2080, 2, 12);
console.log(enYear, enMonth, enDay) // 2023 5 27