Installations
npm install react-date-object
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
16.20.0
NPM Version
8.19.4
Statistics
39 Stars
80 Commits
8 Forks
1 Watching
2 Branches
4 Contributors
Updated on 26 Nov 2024
Bundle Size
20.09 kB
Minified
6.25 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
5,362,676
Last day
3.6%
14,400
Compared to previous day
Last week
4.8%
72,871
Compared to previous week
Last month
9.9%
298,033
Compared to previous month
Last year
68.5%
2,858,350
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Date Object
supported calendars: gregorian
, persian
, arabic
, indian
default: gregorian
supported locales: en
, fa
, ar
, hi
default: en
NodeJs: date-object
Versions before 2.0.0
The way to entering calendars
and locales
for the versions before 2.0.0 is different.
To see the readme file for v1.x click here
1- Install
1-1- npm:
1npm install react-date-object --save
1-2- yarn:
1yarn add react-date-object
2- Usage
1import DateObject from "react-date-object"; 2 3var date = new DateObject(); 4 5console.log(date.format()); //2021/06/10
3- Calendars & Locales
If you want to use a Calendar or a Locale other than Gregorian and English :
Calendars | Gregorian | Persian (Solar Hijri) | Jalali | Arabic (Lunar Hijri) | Indian | |
---|---|---|---|---|---|---|
/calendars/gregorian | /calendars/persian | /calendars/jalali | /calendars/arabic | /calendars/indian | ||
Locales | English | /locales/gregorian_en | /locales/persian_en | /locales/persian_en | /locales/arabic_en | /locales/indian_en |
Portuguese - BRAZIL | gregorian_pt_br | - | - | - | - | |
Farsi | /locales/gregorian_fa | /locales/persian_fa | /locales/persian_fa | /locales/arabic_fa | /locales/indian_fa | |
Arabic | /locales/gregorian_ar | /locales/persian_ar | /locales/persian_ar | /locales/arabic_ar | /locales/indian_ar | |
Hindi | /locales/gregorian_hi | /locales/persian_hi | /locales/persian_hi | /locales/arabic_hi | /locales/indian_hi |
Examples
3-1- Persian Calendar, Farsi Locale
1import DateObject from "react-date-object"; 2import persian from "react-date-object/calendars/persian"; 3import persian_fa from "react-date-object/locales/persian_fa"; 4 5var date = new DateObject({ calendar: persian, locale: persian_fa }); 6 7console.log(date.format()); //Û±Û´Û°Û°/Û°Û³/Û²Û°
3-2- Arabic Calendar, Arabic Locale
1import DateObject from "react-date-object"; 2import arabic from "react-date-object/calendars/arabic"; 3import arabic_ar from "react-date-object/locales/arabic_ar"; 4 5var date = new DateObject({ calendar: arabic, locale: arabic_ar }); 6 7console.log(date.format()); //١٤٤٢/١٠/٢٩
3-3- Indiann Calendar, Hindi Locale
1import DateObject from "react-date-object"; 2import indian from "react-date-object/calendars/indian"; 3import indian_hi from "react-date-object/locales/indian_hi"; 4 5var date = new DateObject({ calendar: indian, locale: indian_hi }); 6 7console.log(date.format()); //१९४३/०३/२०
4- Examples
4-1- new instance
4-1-1- String (year month day hour minute second millisecond meridiem)
1import DateObject from "react-date-object"; 2 3var date = new DateObject("2020 8 21 11 55 36 100 am"); 4 5console.log(date.format("YYYY/MM/DD hh:mm:ss.SSS a")); //2020/08/21 11:55:36.100 am 6 7date = new DateObject("2020/08/01"); 8 9console.log(date.format("YYYY/MM/DD hh:mm:ss.SSS a")); //2020/08/01 12:00:00.000 am
4-1-2- Number (unix time in milliseconds)
1import DateObject from "react-date-object"; 2 3var date = new DateObject(1597994736000); 4 5console.log(date.format("dddd DD MMMM @ hh:mm:ss.SSS a")); //Friday 21 August @ 11:55:36.000 am
4-1-3- JavaScript Date
1import DateObject from "react-date-object"; 2 3var $date = new Date(2019, 8, 20); 4var date = new DateObject($date); 5 6console.log(date.format()); //2019/09/20
4-1-4- DateObject
1import DateObject from "react-date-object"; 2 3var $date = new DateObject("2019/09/20"); 4var date = new DateObject($date); 5 6console.log(date.format()); //2019/09/20
4-1-5- Object
4-1-5-1-
1{ 2 date: String , Number(unix time in milliseconds), Date or DateObject, //default new Date() 3 calendar: Calendar, //default gregorian 4 locale: Locale, //default en 5 format: String, //default `YYYY/MM/DD` 6 ignoreList:Array//If the format contained words that should be ignored 7} 8
1import DateObject from "react-date-object"; 2import persian from "react-date-object/calendars/persian"; 3import persian_fa from "react-date-object/locales/persian_fa"; 4import persian_en from "react-date-object/locales/persian_en"; 5 6var date = new DateObject({ 7 date: new Date(), 8}); 9 10console.log(date.format()); //2020/08/21 11 12date = new DateObject({ 13 date: new Date(), 14 calendar: persian, 15 locale: persian_fa, 16}); 17 18console.log(date.format()); //Û±Û³Û¹Û¹/Û°Ûµ/Û³Û± 19 20date = new DateObject({ 21 date: "31 Mordad 1399", 22 format: "DD MMMM YYYY", 23 calendar: persian, 24 locale: persian_en, 25}); 26 27console.log(date.format()); //31 Mordad 1399
4-1-5-2-
1{ 2 year: Number, 3 month: Number, 4 day: Number, 5 hour: Number, //default 0 6 minute: Number, //default 0 7 second: Number, //default 0 8 millisecond: Number, //default 0 9 calendar: Calendar, //default gregorian 10 locale: Locale, //default en 11 format: String, //default `YYYY/MM/DD` 12 ignoreList:Array//If the format contained words that should be ignored 13} 14
1import DateObject from "react-date-object"; 2import persian from "react-date-object/calendars/persian"; 3import persian_en from "react-date-object/locales/persian_en"; 4import persian_fa from "react-date-object/locales/persian_fa"; 5 6var date = new DateObject({ 7 year: 2020, 8 month: 8, 9 day: 21, 10 hour: 12, 11 minute: 20, 12 second: 36, 13 milisecond: 152, 14 format: "dddd DD MMMM YYYY", 15}); 16 17console.log(date.format()); //Friday 21 August 2020 18 19date = new DateObject({ 20 year: 1399, 21 month: 5, 22 day: 31, 23 calendar: persian, 24 locale: persian_en, 25 format: "dddd DD MMMM YYYY", 26}); 27 28console.log(date.format()); //Jomeh 31 Mordad 1399 29 30date = new DateObject({ 31 year: 1399, 32 month: 5, 33 day: 31, 34 calendar: persian, 35 locale: persian_fa, 36 format: "dddd DD MMMM YYYY", 37}); 38 39console.log(date.format()); //جمعه ۳۱ مرداد ۱۳۹۹
4-2- convert(calendar:Calendar, locale?:Locale)
If you use the convert method without argument, the date will be converted to Gregorian calendar.
The second argument (Locale) is optional.
1import DateObject from "react-date-object"; 2import gregorian from "react-date-object/calendars/gregorian"; 3import persian from "react-date-object/calendars/persian"; 4import arabic from "react-date-object/calendars/arabic"; 5import indian from "react-date-object/calendars/indian"; 6 7var date = new DateObject(); 8 9console.log(date.format()); //2020/10/31 10 11date.convert(persian); 12console.log(date.format()); //1399/08/10 13 14date.convert(arabic); 15console.log(date.format()); //1442/03/14 16 17date.convert(indian); 18console.log(date.format()); //1942/08/09 19 20date.convert(gregorian); //or date.convert() 21console.log(date.format()); //2020/10/31
4-3- format(token:String)
default format is YYYY/MM/DD. to see all format types click here
1import DateObject from "react-date-object"; 2 3var date = new DateObject(); 4 5consoel.log(date.format()); //2020/10/31 6consoel.log(date.format("MM/DD/YYYY")); //10/31/2020 7consoel.log(date.format("MMM/DD/YYYY HH:mm:ss")); //Oct/31/2020 18:17:28 8consoel.log(date.format("dddd DD MMMM YYYY, hh:mm:ss A")); //Saturday 31 October 2020, 06:19:18 PM 9consoel.log(date.format("ddd DD MMM YYYY, hh:mm a")); //Sat 31 Oct 2020, 06:20 pm
formatting with ignore list:
1import DateObject from "react-date-object"; 2 3var date = new DateObject(); 4 5console.log( 6 date.format("hours:HH minutes:mm seconds:ss", ["hours", "minutes", "seconds"]) 7); //hours:12 minutes:22 seconds:40 8 9console.log(date.format("it's HH o'clock", ["it's", "o'clock"])); //it's 12 o'clock 10 11console.log( 12 date.format(`DD MMMM at hh:mm ${date.hour >= 12 ? "Afternoon" : "Morning"}`, [ 13 "at", 14 "Afternoon", 15 "Morning", 16 ]) 17); //11 November at 12:22 Afternoon
4-4- setter methods
1import DateObject from "react-date-object"; 2import gregorian from "react-date-object/calendars/gregorian"; 3import persian from "react-date-object/calendars/persian"; 4import indian from "react-date-object/calendars/indian"; 5import gregorian_en from "react-date-object/locales/gregorian_en"; 6import persian_en from "react-date-object/locales/persian_en"; 7import indian_en from "react-date-object/locales/indian_en"; 8 9var date = new DateObject(); 10 11date 12 .setCalendar(gregorian) 13 .setFormat("YYYY-MM-DD HH:mm:ss.SSS") 14 .setLocale(gregorian_en) 15 .setYear(2020) 16 .setMonth(9) 17 .setDay(21) 18 .setHour(12) 19 .setMinute(20) 20 .setSecond(14) 21 .setMillisecond(200); 22 23console.log(date.format()); //2020-09-21 12:20:14.200 24 25date 26 .setCalendar(persian) 27 .setLocale(persian_en) 28 .setYear(1399) 29 .setMonth(9) 30 .setDay(21) 31 .setFormat("dddd DD MMMM YYYY"); 32 33console.log(date.format()); //Jom'eh 21 Azar 1399 34 35date.setDate(new Date(2020, 9, 27)).setLocale(gregorian_en); //(calendar is set to gregorian) 36 37console.log(date.format()); //Tuesday 27 October 2020 38 39date.setDate( 40 new DateObject({ 41 calendar: indian, 42 locale: indian_en, 43 year: 1942, 44 month: 8, 45 day: 5, 46 }) 47); //format is set based on given DateObject (default:YYYY/MM/DD) 48 49console.log(date.format()); //1942/08/05
4-5- get and set
1import DateObject from "react-date-object"; 2 3var date = new DateObject(); 4 5console.log(date.format()); //2020/08/21 6 7date.year += 2; 8date.month += 2; 9date.day += 2; 10date.hour += 2; 11date.minute += 2; 12date.second += 2; 13date.millisecond += 2; 14 15console.log(date.format()); //2022/10/23 16 17console.log(date.month); 18 19/** 20 * { 21 * name: 'October', 22 * shortName: 'Oct', 23 * length: 31, 24 * index: 9, 25 * number: 10, 26 * toString: [Function (anonymous)] 27 * } 28 */ 29 30console.log(date.weekDay); 31 32/** 33 * { 34 * name: 'Sunday', 35 * shortName: 'Sun', 36 * index: 0, 37 * number: 1, 38 * toString: [Function (anonymous)] 39 * } 40 */ 41 42var { year, month, weekDay, day } = date; 43 44console.log(`${weekDay.name} ${year}/${month}/${day}`); //Sunday 2022/10/23 45 46date.year = 2020; 47date.month = 8; 48date.day = 21; 49 50date.isLeap; //true 51date.isValid; //true 52date.isUTC; //false 53date.month.name; //August 54date.month.length; //31 55date.month.index; //7 56date.month.number; //8 57 58date.weekDay.name; //Friday 59date.weekDay.index; //5 60date.weekDay.number; //6 61 62date.dayOfBeginning; //737658 63date.dayOfYear; //234 64date.daysLeft; //132 65date.weekOfYear; //34 66date.unix; //1597951800 (unix time in seconds) 67 68date.weekDays; // array [{ name: 'Sunday', shortName: 'Sun', ...}] 69date.months; //array [{ name: 'January', shortName: 'Jan', ...}] 70date.leaps; //array [4, 8, 12, 16, 20,...] 71 72date.calendar.name; //gregorian
4-6- parse(date:String)
Remember that parsing date is based on the format you set
1import DateObject from "react-date-object"; 2import persian from "react-date-object/calendars/persian"; 3import persian_en from "react-date-object/locales/persian_en"; 4 5var date = new DateObject(); 6 7date._format = "dddd DD MMMM YYYY"; 8 9date.parse("Monday 24 August 2020"); 10console.log(date.format("YYYY/MM/DD")); //2020/08/24 11 12date.parse("Friday 07 August 2020"); 13console.log(date.format("YYYY-MM-DD")); //2020-08-07 14 15date 16 .setCalendar(persian) 17 .setLocale(persian_en) 18 .setFormat("YYYY/MM/DD") 19 .parse("1399/06/03"); 20console.log(date.format()); //1399/06/03 21 22date.setFormat("YYYY/MM/DD HH:mm").parse("1399/06/03 12:32"); 23console.log(date.format("dddd DD MMMM @ hh:mm a")); //Doshanbeh 03 Shahrivar @ 12:32 pm
4-7- getValue
1import DateObject from "react-date-object"; 2import arabic_ar from "react-date-object/locales/arabic_ar.js"; 3 4var date = new DateObject({ 5 date: "1442/01/01", 6 calendar: arabic, 7 locale: arabic_ar, 8}); 9 10console.log(date.getValue("M")); //1 11console.log(date.format("M")); //Ù¡ 12 13console.log(typeof date.getValue("D")); //number 14console.log(typeof date.format("D")); //string 15 16console.log(Number(date.getValue("YYYY"))); //1442 17console.log(Number(date.format("YYYY"))); //NaN
4-8- add(duration:Number or String,type:String)
Types | ||
---|---|---|
years | year | y |
months | month | M |
days | day | d |
hours | hour | h |
minutes | minute | m |
seconds | second | s |
milliseconds | millisecond | ms |
1import DateObject from "react-date-object"; 2 3var date = new DateObject("2020/10/07 5:35:24 pm"); 4 5date.setFormat("YYYY/MM/DD hh:mm:ss.SSS"); 6 7console.log(date.add(2, "years").format()); //2022/10/07 05:35:24.000 8console.log(date.add("1", "month").format()); //2022/11/07 05:35:24.000 9console.log(date.add(3, "d").format()); //2022/11/10 05:35:24.000 10console.log(date.add(4, "hours").format()); //2022/11/10 09:35:24.000 11console.log(date.add(1, "minute").format()); //2022/11/10 09:36:24.000 12console.log(date.add("20", "s").format()); //2022/11/10 09:36:44.000 13console.log(date.add(100, "milliseconds").format()); //2022/11/10 09:36:44.100
4-9- subtract(duration:Number or String,type:String)
Types | ||
---|---|---|
years | year | y |
months | month | M |
days | day | d |
hours | hour | h |
minutes | minute | m |
seconds | second | s |
milliseconds | millisecond | ms |
1import DateObject from "react-date-object"; 2 3var yesterday = new DateObject().subtract(1, "day");
4-10- set method
4-10-1 set(key:String,value:Any)
1import DateObject from "react-date-object"; 2import indian from "react-date-object/calendars/indian"; 3import persian from "react-date-object/calendars/persian"; 4import indian_hi from "react-date-object/locales/indian_hi"; 5import persian_en from "react-date-object/locales/persian_en"; 6 7var date = new DateObject(); //2020/10/31 8 9console.log(date.set("year", 2021)); //2021/10/31 10console.log(date.set("month", 1)); //2021/01/31 11console.log(date.set("day", 7)); //2021/01/07 12console.log(date.set("format", "MM/DD/YYYY")); //01/07/2021 13console.log(date.set("calendar", indian)); //10/17/1942 14console.log(date.set("locale", indian_hi)); //१०/१à¥/१९४२ 15console.log(date.set("date", new Date())); //2020/10/31 (calendar is set to gregorian) 16console.log( 17 date.set("date", new DateObject({ calendar: persian, locale: persian_en })) 18); //1399/08/10 (calendar & locale is set to given values)
4-10-2 set(object)
1import DateObject from "react-date-object/index"; 2import persian from "react-date-object/calendars/persian"; 3import gregorian from "react-date-object/calendars/gregorian"; 4import persian_en from "react-date-object/locales/persian_en"; 5import gregorian_en from "react-date-object/locales/gregorian_en"; 6 7var date = new DateObject(); //2020/10/31 8 9console.log( 10 date 11 .set({ calendar: persian, locale: persian_en, format: "dddd DD MMMM YYYY" }) 12 .format() 13); //Shanbeh 10 Aban 1399 14 15console.log( 16 date 17 .set({ 18 calendar: gregorian, 19 locale: gregorian_en, 20 year: 2020, 21 month: 11, 22 day: 12, 23 }) 24 .format() 25); //Saturday 12 December 2020 26 27console.log(date.set(new DateObject().toObject()).format()); //2020/10/31 28 29console.log( 30 date.set({ format: "Date:MM/DD/YYYY", ignoreList: ["Date"] }).format() 31); //Date:10/31/2020
4-11- toUTC()
1import DateObject from "react-date-object"; 2import arabic from "react-date-object/calendars/arabic"; 3import gregorian from "react-date-object/calendars/gregorian"; 4import arabic_en from "react-date-object/locales/arabic_en"; 5import gregorian_en from "react-date-object/locales/gregorian_en"; 6 7var date = new Date(); //Wed Oct 14 2020 11:12:18 GMT+0330 8 9var dateObject = new DateObject({ 10 date, 11 calendar: arabic, 12 locale: arabic_en, 13 format: "ddd, DD MMM YYYY HH:mm:ss", 14}); 15 16console.log(dateObject.format()); //Arb, 26 Sa 1442 11:12:18 17 18console.log(` 19dateUTC : ${date.toUTCString()} 20arabicUTC : ${dateObject.toUTC().toString()} 21gregorianUTC : ${dateObject.convert(gregorian, gregorian_en).toString()} 22`); 23 24/** 25 * dateUTC : Wed, 14 Oct 2020 07:42:18 GMT 26 * arabicUTC : Arb, 26 Sa 1442 07:42:18 27 * gregorianUTC : Wed, 14 Oct 2020 07:42:18 28 */
4-12- custom months, week days & digits
See the example below in case you want to use your personal data instead of default months, week days & digits
1import DateObject from "react-date-object"; 2 3var date = new DateObject(); 4 5console.log(date.format("MMMM MMM")); //November Nov 6console.log(date.format("dddd ddd")); //Monday Mon 7console.log(date.format("D")); //2 8 9date.months = [ 10 ["jan", "j"], //[["name","shortName"], ... ] 11 ["feb", "f"], 12 ["mar", "m"], 13 ["apr", "a"], 14 ["may", "m"], 15 ["jun", "j"], 16 ["jul", "j"], 17 ["aug", "a"], 18 ["sep", "s"], 19 ["oct", "o"], 20 ["nov", "n"], 21 ["dec", "d"], 22]; 23 24date.weekDays = [ 25 ["su", "s"], //[["name","shortName"], ... ] 26 ["mo", "m"], 27 ["tu", "t"], 28 ["we", "w"], 29 ["th", "t"], 30 ["fr", "f"], 31 ["sa", "s"], 32]; 33 34/** 35 * This is just a test to display digits. 36 * The Greek number system does not work like this. 37 */ 38date.digits = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]; 39 40console.log(date.format("MMMM MMM")); //nov n 41console.log(date.format("dddd ddd")); //mo m 42console.log(date.format("D")); //II 43 44console.log(date.month); 45 46/** 47 *{ 48 * name: 'nov', 49 * shortName: 'n', 50 * length: 30, 51 * index: 10, 52 * number: 11, 53 * toString: [Function (anonymous)] 54 * valueOf: [Function: valueOf] 55 *} 56 */ 57 58console.log(date.weekDay); 59 60/** 61 *{ 62 * name: 'mo', 63 * shortName: 'm' 64 * index: 1, 65 * number: 2, 66 * toString: [Function: toString], 67 * valueOf: [Function: valueOf] 68 *} 69 */ 70 71console.log(date.digits); 72 73/** 74 * [ 75 * '', 'I', 'II', 76 * 'III', 'IV', 'V', 77 * 'VI', 'VII', 'VIII', 78 * 'IX' 79 * ] 80 */
You can use date.setMonths(months).setWeekDays(weekDays).setDigits(digits)
as well
4-13- other methods
1import DateObject from "react-date-object"; 2 3var date = new DateObject(); 4 5console.log(date.toFirstOfWeek().format()); //2020/08/16 6console.log(date.toFirstOfMonth().format()); //2020/08/01 7console.log(date.toFirstOfYear().format()); //2020/01/01 8console.log(date.toFirstWeekOfYear().format()); //2020/01/05 9console.log(date.toLastOfMonth().format()); //2020/01/31 10console.log(date.toLastOfWeek().format()); //2020/02/01 11console.log(date.toLastOfYear().format()); //2020/12/31 12console.log(date.toLastWeekOfYear().format()); //2020/12/27 13 14console.log(date.toString()); //2020/12/27 15console.log(date.toDate()); //2020-12-27T07:38:34.724Z 16console.log(date.toUnix()); //1609054714 (unix time in seconds) 17console.log(date.toJulianDay()); //2459210 18console.log(date.toObject()); 19/** 20 *{ 21 * year: 2020, 22 * month: { 23 * name: 'December', 24 * shortName: 'Dec', 25 * length: 31, 26 * index: 11, 27 * number: 12, 28 * toString: [Function: toString], 29 * valueOf: [Function: valueOf] 30 * }, 31 * day: 27, 32 * weekDay: { 33 * name: 'Sunday', 34 * shortName: 'Sun', 35 * index: 0, 36 * number: 1, 37 * toString: [Function: toString], 38 * valueOf: [Function: valueOf] 39 * }, 40 * hour: 11, 41 * minute: 8, 42 * second: 34, 43 * millisecond: 724, 44 * weekOfYear: 52, 45 * dayOfYear: 362, 46 * daysLeft: 4, 47 * calendar: { 48 * name: 'gregorian', 49 * startYear: 1, 50 * yearLength: 365, 51 * epoch: 1721424, 52 * century: 20, 53 * weekDaysIndex: [ 54 * 0, 1, 2, 3, 55 * 4, 5, 6 56 * ], 57 * getMonthLengths: [Function: getMonthLengths], 58 * isLeap: [Function: isLeap], 59 * getLeaps: [Function: getLeaps], 60 * getDayOfYear: [Function: getDayOfYear], 61 * getAllDays: [Function: getAllDays], 62 * leapsLength: [Function: leapsLength], 63 * guessYear: [Function: guessYear] 64 * }, 65 * locale: { 66 * months: [ 67 * [Array], [Array], 68 * [Array], [Array], 69 * [Array], [Array], 70 * [Array], [Array], 71 * [Array], [Array], 72 * [Array], [Array] 73 * ], 74 * weekDays: [ 75 * [Array], [Array], 76 * [Array], [Array], 77 * [Array], [Array], 78 * [Array] 79 * ], 80 * digits: [ 81 * '0', '1', '2', '3', 82 * '4', '5', '6', '7', 83 * '8', '9' 84 * ], 85 * meridiems: [ [Array], [Array] ] 86 * }, 87 * format: 'YYYY/MM/DD', 88 * ignoreList: [] 89 *} 90 */ 91console.log(date.toJSON()); //1609054714724 92 93console.log(JSON.stringify({ date })); //{"date":1609054714724} 94console.log(new DateObject(date.toJSON()).format()); //2020/12/27
4-14 valueOf()
returns unix time in milliseconds
1import DateObject from "react-date-object"; 2import persian_calendar from "react-date-object/calendars/persian"; 3import arabic_calendar from "react-date-object/calendars/arabic"; 4import indian_calendar from "react-date-object/calendars/indian"; 5 6var gregorian = new DateObject(); 7var persian = new DateObject({ date: gregorian, calendar: persian_calendar }); 8var arabic = new DateObject({ date: gregorian, calendar: arabic_calendar }); 9var indian = new DateObject({ date: gregorian, calendar: indian_calendar }); 10 11console.log(gregorian.valueOf(), gregorian.format()); //1604824018304 2020/11/08 12console.log(persian.valueOf(), persian.format()); //1604824018304 1399/08/18 13console.log(indian.valueOf(), indian.format()); //1604824018304 1942/08/17 14console.log(arabic.valueOf(), arabic.format()); //1604824018304 1442/03/22 15 16console.log(persian - gregorian === 0); //true
4-15- using calendars, format & locales
1import DateObject from "react-date-object"; 2import gregorian from "react-date-object/calendars/gregorian"; 3import persian from "react-date-object/calendars/persian"; 4import arabic from "react-date-object/calendars/arabic"; 5import persian_fa from "react-date-object/locales/persian_fa"; 6import gregorian_en from "react-date-object/locales/gregorian_en"; 7 8var date = new DateObject({ 9 calendar: gregorian, 10 format: "dddd DD MMMM", 11}); 12 13console.log(date.format()); //Friday 21 August 14 15date.calendar = persian; 16date.locale = persian_fa; //جمعه 31 مرداد 17console.log(date.format()); 18 19date._format = "YY/MM/DD"; 20console.log(date.format()); //۹۹/۰۵/۳۱ 21 22date.setCalendar(gregorian).setLocale(gregorian_en); 23console.log(date.format()); //20/08/21 24 25date = new DateObject(new Date()); 26 27console.log(date.convert(persian).format()); //1399/05/31 28console.log(date.convert(arabic).format()); //1442/01/02
5- Formatting Tokens
Token | Example | Description | Availability (Parse /Format) |
---|---|---|---|
YYYY | 2020 | full year | both |
YY | 20 | 2 digits year | both |
MMMM | December | month name | both |
MMM | Dec | month short name | both |
MM | 03, 09, 10, ... | 2 digits month number | both |
M | 3, 9, 10, ... | month number | both |
DDDD | 09 | day of year | format |
DDD | 9 | day of year | format |
DD | 03, 09, 10, 17, ... | 2 digits day of month | both |
D | 3, 9 ,10, 17 | day of month | both |
WW | 01, 03, 24, 33, ... | week of year | format |
W | 1, 3, 24. 33, ... | week of year | format |
dddd | Saturday, Sunday, Monday, ... | week day name | format |
ddd | Sat, Sun, Mon, ... | week day short name | format |
dd | 01,02,...,07 | 2 digits week day number | format |
d | 1,2,...,7 | week day number | format |
HH | 03, 09, 10, 17,... | 2 digits hour (24 hour mode) | both |
H | 3, 9, 10, 17,... | hour (24 hour mode) | both |
hh | 03, 09, 10, 17,... | 2 digits hour (12 hour mode) | both |
h | 3, 9, 10, 17,... | hour (12 hour mode) | both |
mm | 03, 09, 10, 17,... | 2 digits minute | both |
m | 3, 9, 10, 17,... | minute | both |
ss | 03, 09, 10, 17,... | 2 digits second | both |
s | 3, 9, 10, 17,... | second | both |
SSS | 100 | 3 digits millisecond | both |
SS | 10 | 2 digits millisecond | both |
S | 1 | 1 digit millisecond | both |
A | AM | meridiem | both |
a | am | meridiem lowercase | both |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
Reason
Found 3/25 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Score
2.9
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-date-object
@internationalized/date
Internationalized calendar, date, and time manipulation utilities
is-date-object
Is this value a JS Date object? This module works cross-realm/iframe, and despite ES6 @@toStringTag.
universal-cookie
Universal cookies for JavaScript
react-datepicker
A simple and reusable datepicker component for React