Create & Parse

                
let now = new PersianDate(); // without parameter returns now

let fromDate = new PersianDate(new Date(2021, 0, 1, 0, 0, 0, 0));

let fromArray = new PersianDate([2021, 1, 1, 0, 0, 0, 0]); // [year,month,date,hour,minute,second,millisecond]

let fromObject = new PersianDate({
    year:2021,      // or [y, years]
    month:1,        // or [M, months]
    date:1,         // or [d, day, days]
    hour:0,         // or [h, hours]
    minute:0,       // or [m, minutes]
    second:0,       // or [s, second]
    millisecond:0   // or [ms,milliseconds]
});

let fromTimestamp = new PersianDate(1609446600000); // with timestamp

let fromString = new PersianDate("2021-1-1");

let fromJalali = new PersianDate("1400/1/1","jalali");

                
            

If you want to use the Jalali date for the first parameter, you must pass the 'jalali' or 'j' in the second parameter

For string dates you can use this seperators ['/',' ','-','.',',',':']

Calendar 2.0.0+

PersianDate supports the Persian (Jalali) and Gregorian calendar.

You can set the calendar in the creation time of instance or use the calendar method.

                
let nowruz = new PersianDate('1400','jalali');
                
            

If you pass the 'jalali', the date also must be the Jalali date

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

p.calendar('j').toString(); // 1399/10/12

p.calendar(); // jalali
            
        
            
let now = new PersianDate();

now.calendar('g').toString(); // {{ today.clone().now().calendar('g').toString() }}

now.calendar(); // gregorian
            
        

The default calendar of PersianDate is Jalali

Now 1.0.0+

To get the current date and time, you can use the new PersianDate() and now method.

            
let now = new PersianDate();

now.toString(); // {{ today.clone().now().toString() }}
            
        
            
let p = new PersianDate('2021');

p.now().toString(); // {{ today.clone().now().toString() }}
            
        

Parse 1.0.0+

You can set the new date for the instance with parse method.

If you use the 'jalali' calendar, you must pass the Jalali date and if you use the 'gregorian' calendar, you must pass the Gregorian date

            
let p = new PersianDate();

p.parse('1400/1/1 12:30').toString('datetime'); // 1400/01/01 12:30

p.parse(1400,2,10).toString(); // 1400/02/10

p.parse([1400,3,15,12,30]).toString('datetime'); // 1400/03/15 12:30

p.parse({
    y:1400,
    M:4,
    d:20
}).toString(); // 1400/04/20

p.calendar('gregorian').parse('2021-1-1').toString() // 2021-01-01
            
        
            
let p = new PersianDate('2021');

p.now().toString(); // {{ today.clone().now().toString() }}
            
        

From Jalali date 2.0.0+

You can set the date from Jalali date with fromJalali method.

            
let p = new PersianDate();

p.fromJalali('1400/1/1').toString(); // 1400/01/01

p.calendar('g').fromJalali([1400,1,1]).toString(); // 2021/03/21
            
        

From Gregorian date 2.0.0+

You can set the date from Gregorian date with fromGregorian method.

            
let p = new PersianDate();

p.fromGregorian('2021-1-1').toString(); // 1399/10/12

p.calendar('g').fromGregorian([2021,1,1]).toString(); // 2021-01-01
            
        

Time 2.3.0+

You can change the time with time method.

            
let p = new PersianDate();

p.time('12:30:25').toString('time:ss'); // 12:30:25

p.time(20,18).toString('time'); // 20:18
            
        

Clone 1.1.0+

get the clone of this instance.

            
let p = new PersianDate('1400/1/1','j');

let clone = p.clone();

p.year(1399);

clone.toString(); // 1400/01/01