JDate class

An instant in time, such as 1377-02-16, 8:18pm.

JDate can represent time values that are at a distance of at most 100,000,000 days from epoch (1348-10-11 UTC): -272442-01-10 to 275139-07-12. Crossing this limit will cause DateTime is outside valid range exception.

Create a JDate object by using one of the constructors or by parsing a correctly formatted string. Note that hours are specified between 0 and 23, as in a 24-hour clock. For example:

var now = new JDate.now();
var dayInPast = new JDate.utc(1377, 3, 14);
var dayInNearFuture = JDate.parse("1405-01-01 20:18:04Z");

A JDate object is anchored either in the UTC time zone or in the local time zone of the current computer when the object is created.

You can use properties to get the individual units of a JDate object.

assert(dayInPast.month == 3);
assert(dayInNearFuture.second == 4);

Day and month values begin at 1.

Working with UTC and local time

A JDate object is in the local time zone unless explicitly created in the UTC time zone.

var dDay = new JDate.utc(1944, 6, 6);

Use isUtc to determine whether a JDate object is based in UTC. Use the methods toLocal and toUtc to get the equivalent date/time value specified in the other time zone. Use timeZoneName to get an abbreviated name of the time zone for the JDate object. To find the difference between UTC and the time zone of a JDate object call timeZoneOffset.

Comparing JDate objects

The JDate class contains several handy methods, such as isAfter, isBefore, and isAtSameMomentAs, for comparing JDate objects.

assert(dayInPast.isAfter(dayInNearFuture) == false);
assert(dayInPast.isBefore(dayInNearFuture) == true);

Using JDate with Duration

Use the add and subtract methods with a Duration object to create a new JDate object based on another. For example, to find the date that is sixty days (24 * 60 hours) after today, write:

var now = new JDate.now();
var sixtyDaysFromNow = now.add(new Duration(days: 60));

To find out how much time is between two JDate objects use difference, which returns a Duration object:

var difference = dayInPast.difference(dayInNearFuture);
print(difference.inDays);
Implemented types

Constructors

JDate(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0, int microsecond = 0])
Constructs a JDate instance specified in the local time zone.
JDate.fromDateTime(DateTime date)
Constructs a JDate instance from given DateTime.
JDate.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch, {bool isUtc = false})
Constructs a new JDate instance with the given microsecondsSinceEpoch.
JDate.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, {bool isUtc = false})
Constructs a new JDate instance with the given millisecondsSinceEpoch.
JDate.now()
Constructs a JDate instance with current date and time in the local time zone.
JDate.utc(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0, int microsecond = 0])
Constructs a JDate instance specified in the UTC time zone.

Properties

day int
The day of the month 1..31.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hour int
The hour of the day, expressed as in a 24-hour clock 0..23.
getter/setter pair
isLeapYear bool
True if this JDate.year is a leap year.
no setter
isUtc bool
True if this JDate is set to UTC time.
no setter
microsecond int
The microsecond 0...999.
getter/setter pair
microsecondsSinceEpoch int
The number of microseconds since the 'Unix epoch' 1970-01-01T00:00:00Z (UTC).
getter/setter pair
millisecond int
The millisecond 0...999.
getter/setter pair
millisecondsSinceEpoch int
The number of milliseconds since the 'Unix epoch' 1970-01-01T00:00:00Z (UTC).
getter/setter pair
minute int
The minute 0...59.
getter/setter pair
month int
The month 1..12.
getter/setter pair
monthLength int
Returns number of days in that month.
no setter
monthName String
Returns the name of month in persian.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
second int
The second 0...59.
getter/setter pair
shortYear int
Returns the short version of year.
no setter
timeZoneName String
The time zone name.
no setter
timeZoneOffset Duration
The time zone offset, which is the difference between local time and UTC.
no setter
weekday int
The day of the week شنبه..جمعه.
no setter
weekdayName String
Returns the name of weekDay in persian.
no setter
year int
The year.
getter/setter pair

Methods

add(Duration duration) JDate
Returns a new JDate instance with duration added to this.
changeTo({int? year, int? month, int? day, int? hour, int? minute, int? second, int? millisecond, int? microsecond, bool? isUtc}) JDate
Change a JDate instance to specified parameters. returns currently changed JDate
compareTo(JDate other) int
Compares this JDate object to other, returning zero if the values are equal.
override
difference(JDate other) Duration
Returns a Duration with the difference when subtracting other from this.
echo([String format = 'l، d F Y ساعت H:i:s']) String
Turns JDate to String base on format.
isAfter(JDate other) bool
Returns true if this occurs after other.
isAtSameMomentAs(JDate other) bool
Returns true if this occurs at the same moment as other.
isBefore(JDate other) bool
Returns true if this occurs before other.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
subtract(Duration duration) JDate
Returns a new JDate instance with duration subtracted from this.
toDateTime() DateTime
Converts this JDate to a DateTime object with gregorian date.
toIso8601String() String
Returns an ISO-8601 full-precision extended format representation.
toLocal() JDate
Returns this JDate value in the local time zone.
toString() String
Returns a human-readable string for this instance.
override
toUtc() JDate
Returns this JDate value in the UTC time zone.

Operators

operator <(JDate other) bool
Compares two JDate base on their microsecondsSinceEpoch (millisecondsSinceEpoch if running on js environment)
operator <=(JDate other) bool
Compares two JDate base on their microsecondsSinceEpoch (millisecondsSinceEpoch if running on js environment)
operator ==(dynamic other) bool
Returns true if other is a JDate at the same moment and in the same time zone (UTC or local).
override
operator >(JDate other) bool
Compares two JDate base on their microsecondsSinceEpoch (millisecondsSinceEpoch if running on js environment)
operator >=(JDate other) bool
Compares two JDate base on their microsecondsSinceEpoch (millisecondsSinceEpoch if running on js environment)

Static Methods

gregorianToIslamic(int year, int month, int day) BasicDate
Convert Gregorian (Miladi) Date to Islamic (Persian Hijri Qamari) Date and returns a BasicDate
gregorianToJalali(int year, int month, int day) BasicDate
Convert Gregorian (Miladi) Date to Jalali (Shamsi) Date and returns a BasicDate
gregorianToUmmalqura(int year, int month, int day) BasicDate
Convert Gregorian (Miladi) Date to Ummalqura (Arabic Hijri Qamari) Date and returns a BasicDate
islamicToGregorian(int year, int month, int day) BasicDate
Convert Islamic (Persian Hijri Qamari) Date to Gregorian (Miladi) Date and returns a BasicDate
islamicToJalali(int year, int month, int day) BasicDate
Convert Islamic (Persian Hijri Qamari) Date to Jalali (Shamsi) Date and returns a BasicDate
jalaliToGregorian(int year, int month, int day) BasicDate
Convert Jalali (Shamsi) Date to Gregorian (Miladi) Date and returns a BasicDate
jalaliToIslamic(int year, int month, int day) BasicDate
Convert Jalali (Shamsi) Date to Islamic (Persian Hijri Qamari) Date and returns a BasicDate
jalaliToUmmalqura(int year, int month, int day) BasicDate
Convert Jalali (Shamsi) Date to Ummalqura (Arabic Hijri Qamari) Date and returns a BasicDate
parse(String string) JDate
Constructs a new JDate instance based on string.
tryParse(String string) JDate?
Constructs a new DateTime instance based on string.
ummalquraToGregorian(int year, int month, int day) BasicDate
Convert Ummalqura (Arabic Hijri Qamari) Date to Gregorian (Miladi) Date and returns a BasicDate
ummalquraToJalali(int year, int month, int day) BasicDate
Convert Ummalqura (Arabic Hijri Qamari) Date to Jalali (Shamsi) Date and returns a BasicDate