jdate.js
v2.1.6
Published
Simple yet flexible Typescript | Javascript jalali date and time for developers ...
Downloads
17
Maintainers
Readme
Typescript | Javascript JDate Class ;)
Installation
npm i jdate.js
Usage
Typescript
import 'jdate.js';
let date = new Date();
console.log("Normal format: " + date.echo("Y/m/d"));
console.log("Jalali format: " + date.echoFa("Y/m/d"));
ECMAScript
require('jdate.js');
let date = new Date();
console.log("Normal format: " + date.echo("Y/m/d"));
console.log("Jalali format: " + date.echoFa("Y/m/d"));
Browser
<script src="https://cdn.jsdelivr.net/npm/jdate.js"></script>
<script type="text/javascript">
(function() {
var date = new Date();
console.log("Normal format: " + date.echo("Y/m/d"));
console.log("Jalali format: " + date.echoFa("Y/m/d"));
})();
</script>
new Date()
Now with new Date() creates a new gregorian and jalali date object with the current date and time:
var date = new Date();
console.log( date.echoFa() );
console.log( date.echo() );
console.log( date );
~~> شنبه، 25 دی 1400 - 19:22:22
~~> Saturday January 15 2022 - 19:22:22
~~> Sat Jan 15 2022 19:22:22 GMT+0330 (Iran Standard Time)
new Date(...).echo | echoFa
var date = new Date(2019, 4, 3, 10, 33, 30, 0);
console.log( date.echoFa("l، j F Y - H:i:s") );
console.log( date.echo("l، j F Y - H:i:s") );
~~> جمعه، 13 اردیبهشت 1398 - 10:33:30
~~> Friday، 3 May 2019 - 10:33:30
Format guide
Date.parseJalali(...)
You can parse specified shamsi or gregorian date from valid date string to convert it to milliseconds.
Date.parseJalali("1399"); ~~> 1584662400000 ~~> 1399/01/01 - 03:30:00
Date.parseJalali("1399/02"); ~~> 1587324600000 ~~> 1399/02/01 - 00:00:00
Date.parseJalali("1399/02/13"); ~~> 1588361400000 ~~> 1399/02/13 - 00:00:00
Date.parseJalali("1399/02/13 03:14:30"); ~~> 1588373070000 ~~> 1399/02/13 - 03:14:30
Date.parseJalali("2019/05/03 01:02:03"); ~~> 1556829123000 ~~> 1398/02/13 - 01:02:03
new Date(
Date.parseJalali("1993/05/03 03:01:03")
).echoFa("Y/m/d - H:i:s") ~~> 1372/02/13 - 03:01:03
Get Jalali Date Methods
These methods can be used for getting information from a date object as a jalali date:
Set Jalali Date Methods
These methods can be used for set jalali date values (years, months, days, hours, minutes, seconds, milliseconds) for a date object:
License
JDate.js is available under the MIT license.