@Immutable public final class PersianDateTime extends java.lang.Object implements java.time.chrono.ChronoLocalDateTime<PersianDate>
PersianDate and LocalTime to encapsulate these classes in one class for the sake
of simplicity and convenience.
This class is immutable and can be used in multi-threaded environments.
| Modifier and Type | Method and Description |
|---|---|
java.time.chrono.ChronoZonedDateTime<PersianDate> |
atZone(java.time.ZoneId zoneId) |
int |
compareTo(java.time.chrono.ChronoLocalDateTime<?> other) |
boolean |
equals(java.lang.Object obj) |
static PersianDateTime |
from(java.time.temporal.TemporalAccessor temporal)
Obtains an instance of this class from the given temporal object.
|
static PersianDateTime |
fromGregorian(java.time.LocalDateTime localDateTime)
Returns a new instance of Persian date-time, where the date part of the given date-time gets converted to Persian
date, and the time part of the returned date-time will remain unchanged.
|
long |
getLong(java.time.temporal.TemporalField field)
Returns the
long value of this date-time for the given temporal field. |
int |
hashCode() |
boolean |
isSupported(java.time.temporal.TemporalField field) |
static PersianDateTime |
now()
Returns an instance of this class with the actual current date and time.
|
static PersianDateTime |
of(int year,
int month,
int dayOfMonth,
int hour,
int minute)
Obtains an instance of
PersianDateTime with the given parameters, having second and nanosecond set to
zero. |
static PersianDateTime |
of(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second)
Obtains an instance of
PersianDateTime with the given parameters, having nanosecond set to zero. |
static PersianDateTime |
of(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second,
int nanoOfSecond)
Obtains an instance of
PersianDateTime with the given parameters. |
static PersianDateTime |
of(int year,
PersianMonth month,
int dayOfMonth,
int hour,
int minute)
Obtains an instance of
PersianDateTime with the given parameters, having second and nanosecond set to
zero. |
static PersianDateTime |
of(int year,
PersianMonth month,
int dayOfMonth,
int hour,
int minute,
int second)
Obtains an instance of
PersianDateTime with the given parameters, having nanosecond set to zero. |
static PersianDateTime |
of(int year,
PersianMonth month,
int dayOfMonth,
int hour,
int minute,
int second,
int nanoOfSecond)
Obtains an instance of
PersianDateTime with the given parameters. |
static PersianDateTime |
of(PersianDate date,
java.time.LocalTime time)
Obtains a new instance of this class with the given date and time.
|
static PersianDateTime |
parse(java.lang.CharSequence text)
Parses the given string into its corresponding Persian date-time.
|
static PersianDateTime |
parse(java.lang.CharSequence text,
java.time.format.DateTimeFormatter formatter)
Parses the given string with the given formatter into its corresponding Persian date-time.
|
java.time.chrono.ChronoLocalDateTime<PersianDate> |
plus(long amountToAdd,
java.time.temporal.TemporalUnit temporalUnit) |
java.time.LocalDateTime |
toGregorian()
Returns the corresponding Gregorian date-time of this Persian date-time.
|
PersianDate |
toLocalDate()
Returns the date part of this date-time.
|
java.time.LocalTime |
toLocalTime()
Returns the time part of this date-time.
|
java.lang.String |
toString()
Returns the string representation of this date-time.
|
long |
until(java.time.temporal.Temporal temporal,
java.time.temporal.TemporalUnit temporalUnit) |
java.time.chrono.ChronoLocalDateTime<PersianDate> |
with(java.time.temporal.TemporalField field,
long newValue) |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitpublic static PersianDateTime now()
public static PersianDateTime of(PersianDate date, java.time.LocalTime time)
date - the date, not nulltime - the time, not nullpublic static PersianDateTime of(int year, PersianMonth month, int dayOfMonth, int hour, int minute)
PersianDateTime with the given parameters, having second and nanosecond set to
zero.year - the year to represent, from 1 to MAX_YEARmonth - the Persian month, not nulldayOfMonth - the dayOfMonth to represent, from 1 to 31hour - the hour of the day, from 0 to 23minute - the minute of the hour, from 0 to 59PersianDateTimejava.time.DateTimeException - if the passed parameters do not form a valid date or timepublic static PersianDateTime of(int year, PersianMonth month, int dayOfMonth, int hour, int minute, int second)
PersianDateTime with the given parameters, having nanosecond set to zero.year - the year to represent, from 1 to MAX_YEARmonth - the Persian month, not nulldayOfMonth - the dayOfMonth to represent, from 1 to 31hour - the hour of the day, from 0 to 23minute - the minute of the hour, from 0 to 59second - the second of minute, from 0 to 59PersianDateTimejava.time.DateTimeException - if the passed parameters do not form a valid date or timepublic static PersianDateTime of(int year, PersianMonth month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)
PersianDateTime with the given parameters.year - the year to represent, from 1 to MAX_YEARmonth - the Persian month, not nulldayOfMonth - the dayOfMonth to represent, from 1 to 31hour - the hour of the day, from 0 to 23minute - the minute of the hour, from 0 to 59second - the second of minute, from 0 to 59nanoOfSecond - the nanosecond of second, from 0 to 999,999,999PersianDateTimejava.time.DateTimeException - if the passed parameters do not form a valid date or time.public static PersianDateTime of(int year, int month, int dayOfMonth, int hour, int minute)
PersianDateTime with the given parameters, having second and nanosecond set to
zero.year - the year to represent, from 1 to MAX_YEARmonth - the value of month, from 1 to 12dayOfMonth - the dayOfMonth to represent, from 1 to 31hour - the hour of the day, from 0 to 23minute - the minute of the hour, from 0 to 59PersianDateTimejava.time.DateTimeException - if the passed parameters do not form a valid date or time.public static PersianDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second)
PersianDateTime with the given parameters, having nanosecond set to zero.year - the year to represent, from 1 to MAX_YEARmonth - the value of month, from 1 to 12dayOfMonth - the dayOfMonth to represent, from 1 to 31hour - the hour of the day, from 0 to 23minute - the minute of the hour, from 0 to 59second - the second of the minute, from 0 to 59PersianDateTimejava.time.DateTimeException - if the passed parameters do not form a valid date or time.public static PersianDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)
PersianDateTime with the given parameters.year - the year to represent, from 1 to MAX_YEARmonth - the value of month, from 1 to 12dayOfMonth - the dayOfMonth to represent, from 1 to 31hour - the hour of the day, from 0 to 23minute - the minute of the hour, from 0 to 59second - the second of the minute, from 0 to 59nanoOfSecond - the nanosecond of the second, from 0 to 999,999,999PersianDateTimejava.time.DateTimeException - if the passed parameters do not form a valid date or time.public static PersianDateTime fromGregorian(java.time.LocalDateTime localDateTime)
localDateTime - the Gregorian local date time, not nullpublic static PersianDateTime parse(java.lang.CharSequence text)
DateTimeFormatter.ISO_LOCAL_DATE_TIME. For example this is an accepted input string: 1401-06-10T08:35:11.text - the input string with DateTimeFormatter.ISO_LOCAL_DATE_TIME, not nulljava.time.DateTimeException - if the format of the given string is not DateTimeFormatter.ISO_LOCAL_DATE_TIMEDateTimeFormatter.ISO_LOCAL_DATE_TIMEpublic static PersianDateTime parse(java.lang.CharSequence text, java.time.format.DateTimeFormatter formatter)
text - the input string with the given formatter pattern, not nullformatter - the formatter to parse the string from, not nulljava.time.DateTimeException - if the format of the given string is unexpectedDateTimeFormatterpublic static PersianDateTime from(java.time.temporal.TemporalAccessor temporal)
from in interface java.time.chrono.ChronoLocalDateTime<PersianDate>temporal - the temporal object to convert, not nullnulljava.time.DateTimeException - if unable to convert to a PersianDatepublic PersianDate toLocalDate()
toLocalDate in interface java.time.chrono.ChronoLocalDateTime<PersianDate>public java.time.LocalTime toLocalTime()
toLocalTime in interface java.time.chrono.ChronoLocalDateTime<PersianDate>public java.time.LocalDateTime toGregorian()
public boolean isSupported(java.time.temporal.TemporalField field)
isSupported in interface java.time.chrono.ChronoLocalDateTime<PersianDate>isSupported in interface java.time.temporal.TemporalAccessorpublic long getLong(java.time.temporal.TemporalField field)
long value of this date-time for the given temporal field.getLong in interface java.time.temporal.TemporalAccessorfield - the temporal field, not nulllong value of this date-time for the given temporal fieldPersianDate.getLong(TemporalField),
LocalTime.getLong(TemporalField)public java.time.chrono.ChronoLocalDateTime<PersianDate> with(java.time.temporal.TemporalField field, long newValue)
with in interface java.time.chrono.ChronoLocalDateTime<PersianDate>with in interface java.time.temporal.Temporalpublic java.time.chrono.ChronoLocalDateTime<PersianDate> plus(long amountToAdd, java.time.temporal.TemporalUnit temporalUnit)
plus in interface java.time.chrono.ChronoLocalDateTime<PersianDate>plus in interface java.time.temporal.Temporalpublic long until(java.time.temporal.Temporal temporal,
java.time.temporal.TemporalUnit temporalUnit)
until in interface java.time.temporal.Temporalpublic java.time.chrono.ChronoZonedDateTime<PersianDate> atZone(java.time.ZoneId zoneId)
atZone in interface java.time.chrono.ChronoLocalDateTime<PersianDate>public int compareTo(java.time.chrono.ChronoLocalDateTime<?> other)
compareTo in interface java.lang.Comparable<java.time.chrono.ChronoLocalDateTime<?>>compareTo in interface java.time.chrono.ChronoLocalDateTime<PersianDate>public boolean equals(java.lang.Object obj)
equals in interface java.time.chrono.ChronoLocalDateTime<PersianDate>equals in class java.lang.Objectpublic int hashCode()
hashCode in interface java.time.chrono.ChronoLocalDateTime<PersianDate>hashCode in class java.lang.Objectpublic java.lang.String toString()
PersianDateTime dt = PersianDateTime.of(1400, PersianMonth.AZAR, 28, 14, 20, 56);
System.out.println(dt.toString()); // 1400-09-28T14:20:56
Based on the available fields for the time, the format of output string will differ.
toString in interface java.time.chrono.ChronoLocalDateTime<PersianDate>toString in class java.lang.ObjectPersianDate.toString(),
LocalTime.toString()Copyright © 2021. All rights reserved.