Set & Get

Year 1.0.0+

Jalali calendar

                
let p = new PersianDate('1400/2/21','jalali');

p.year(1398).toString(); // 1398/02/21

p.year(); // 1398
                
        

Gregorian calendar

                
let p = new PersianDate('2021-2-21','gregorian');

p.year(2018).toString(); // 2018-02-21

p.year(); // 2018
                
        

You can use the year formats in this method.

            
let p = new PersianDate('2021-5');

p.year('YY'); // 21

p.year('jYY'); // 00

p.year('not a year format'); // if you use like this, returns the year with default format
            
        

Month 1.0.0+

Jalali calendar

                
let p = new PersianDate('1400/2/21','jalali');

p.month(5).toString(); // 1400/05/21

p.month(); // 5
                
        

Gregorian calendar

                
let p = new PersianDate('2021-2-21','gregorian');

p.month(5).toString(); // 2018-05-21

p.month(); // 5
                
        

You can use the month formats in this method.

            
let p = new PersianDate('2021-5');

p.month('MMMM'); // May

p.month('jMMMM'); // اردیبهشت

p.month('not a month format'); // if you use like this, returns the month with default format
            
        

Date 1.0.0+

Jalali calendar

                
let p = new PersianDate('1400/2/21','jalali');

p.date(24).toString(); // 1400/02/24

p.date(); // 24
                
        

Gregorian calendar

                
let p = new PersianDate('2021-2-21','gregorian');

p.date(24).toString(); // 2018-02-24

p.date(); // 24
                
        

You can use the date formats in this method.

            
let p = new PersianDate('2021-5');

p.date('dddd'); // Saturday

p.date('jdddd'); // شنبه

p.date('not a date format'); // if you use like this, returns the date with default format
            
        

Quarter 1.0.0+

Jalali calendar

                
let p = new PersianDate('1400/2/21','jalali');

p.quarter(3).toString(); // 1400/07/21

p.quarter(); // 3
                
        

Gregorian calendar

                
let p = new PersianDate('2021-2-21','gregorian');

p.quarter(3).toString(); // 2018-07-21

p.quarter(); // 3
                
        

You can use the quarter formats in this method.

            
let p = new PersianDate('2021-5');

p.quarter('QO'); // 2nd

p.quarter('jQO'); // اولین

p.quarter('not a quarter format'); // if you use like this, returns the quarter with default format
            
        

Week 1.0.0+

Jalali calendar

                
let p = new PersianDate('1400/2/21','jalali');

p.week(3).toString(); // 1400/01/17

p.week(); // 3
                
        

Gregorian calendar

                
let p = new PersianDate('2021-2-21','gregorian');

p.week(3).toString(); // 2021-01-17

p.week(); // 3
                
        

You can use the week formats in this method.

            
let p = new PersianDate('2021-5');

p.week('W'); // 17

p.week('jW'); // 6

p.week('not a week format'); // if you use like this, returns the week with default format
            
        

Hour 1.0.0+

Jalali calendar

                
let p = new PersianDate('1400/2/21','jalali');

p.hour(15).toString('datetime'); // 1400/02/21 15:00

p.hour(); // 15
                
        

Gregorian calendar

                
let p = new PersianDate('2021-2-21','gregorian');

p.hour(15).toString('datetime'); // 2021-02-21 15:00

p.hour(); // 15
                
        

You can use the hour formats in this method.

            
let p = new PersianDate('2021-5-1 17:00');

p.hour('hh'); // 05

p.hour('not a hour format'); // if you use like this, returns the hour with default format
            
        

Minute 1.0.0+

Jalali calendar

                
let p = new PersianDate('1400/2/21','jalali');

p.minute(34).toString('datetime'); // 1400/02/21 00:34

p.minute(); // 34
                
        

Gregorian calendar

                
let p = new PersianDate('2021-2-21','gregorian');

p.minute(34).toString('datetime'); // 2021-02-21 00:34

p.minute(); // 34
                
        

You can use the minute formats in this method.

            
let p = new PersianDate('2021-5-1 17:12');

p.minute('mm'); // 12

p.minute('not a minute format'); // if you use like this, returns the minute with default format
            
        

Second 1.0.0+

Jalali calendar

                
let p = new PersianDate('1400/2/21','jalali');

p.second(43).toString('datetime:ss'); // 1400/02/21 00:00:43

p.second(); // 43
                
        

Gregorian calendar

                
let p = new PersianDate('2021-2-21','gregorian');

p.second(43).toString('datetime:ss'); // 2021-02-21 00:00:43

p.second(); // 43
                
        

You can use the second formats in this method.

            
let p = new PersianDate('2021-5-1 17:12:26');

p.second('s'); // 26

p.second('not a second format'); // if you use like this, returns the second with default format
            
        

Millisecond 1.0.0+

Jalali calendar

                
let p = new PersianDate('1400/2/21','jalali');

p.millisecond(165).toString('datetime:ss.c'); // 1400/02/21 00:00:00.165

p.millisecond(); // 165
                
        

Gregorian calendar

                
let p = new PersianDate('2021-2-21','gregorian');

p.millisecond(165).toString('datetime:ss.c'); // 2021-02-21 00:00:00.165

p.millisecond(); // 165
                
        

You can use the millisecond formats in this method.

            
let p = new PersianDate('2021-5-1 17:12:26.12');

p.millisecond('CCCC'); // 012

p.millisecond('not a millisecond format'); // if you use like this, returns the millisecond with default format
            
        

Timestamp 1.0.0+

Get the timestamp (the number of milliseconds since 1 January 1970 00:00:00) or set the date from timestamp.

Also you can use the valueOf method for get the timestamp.

            
let p = new PersianDate('2021');

p.timestamp(); // 1609446600000

p.timestamp(1577824200000).toString('YYYY-MM-DD'); // 2020-01-01
            
        

Start of 2.0.0+

Set the date to start of a unit of time.

            
let p = new PersianDate('1400/4/25 12:30','j');

p.startOf('hour').toString('datetime'); // 1400/04/25 12:00

p.startOf('year').toString('datetime'); // 1400/01/01 00:00
            
        

1. The default value of argument is 'year'

2. The argument values is: [ 'y', 'year' ], [ 'M', 'month' ], [ 'd', 'date' ], [ 'h', 'hour' ], [ 'm', 'minute' ], [ 's', 'second' ] and [ 'ms', 'millisecond' ]

End of 2.0.0+

Set the date to end of a unit of time.

            
let p = new PersianDate('1400/4/25 12:30','j');

p.endOf('hour').toString('datetime'); // 1400/04/25 12:59

p.endOf('year').toString('datetime'); // 1400/12/29 23:59
            
        

Like startOf method:

1. The default value of argument is 'year'

2. The argument values is: [ 'y', 'year' ], [ 'M', 'month' ], [ 'd', 'date' ], [ 'h', 'hour' ], [ 'm', 'minute' ], [ 's', 'second' ] and [ 'ms', 'millisecond' ]

Days in month 1.0.0+

get the number of days in a month.

            
PersianDate.getDaysInMonth('jalali', 1399, 12); // 30
PersianDate.getDaysInMonth('gregorian', 2020, 2); // 29


let p = new PersianDate();

p.parse('1399/12').getDaysInMonth(); // 30
p.parse('1400/12').getDaysInMonth(); // 29

p.calendar('gregorian')

p.parse('2020-2').getDaysInMonth(); // 29
p.parse('2021-2').getDaysInMonth(); // 28
            
        
OR
            
p.calendar('j').getDaysInMonth(1400,10); // 30
            
        

Weeks in year 2.0.0+

get the number of weeks in a year.

            
let p = new PersianDate();

p.parse('1398').getWeeksInYear(); // 53

p.parse('1399').getWeeksInYear(); // 52

p.calendar('gregorian')

p.parse('2020').getWeeksInYear(); // 53

p.parse('2021').getWeeksInYear(); // 52
            
        
OR
            
p.calendar('j').getWeeksInYear(1400); // 52
            
        

valueOf method 2.0.0+

get the timestamp.

            
let p = new PersianDate('2021');

p.valueOf(); // 1609446600000