// Time4A => Android PlainDate gdate = jalali.transform(PlainDate.class); Moment m1 = gdate.atStartOfDay().inTimezone(ASIA.TEHRAN); java.util.Date jud = TemporalType.JAVA_UTIL_DATE.from(m1); // Android => Time4A java.util.Date input = new java.util.Date(); Moment m2 = TemporalType.JAVA_UTIL_DATE.translate(input); jalali = m2.toZonalTimestamp(ASIA.TEHRAN).toDate().transform(PersianCalendar.class);
private PlainTimestamp handleMidnight24(PlainTimestamp entity) { PlainDate date = entity.getCalendarDate(); switch (this.mode) { case ElementOperator.OP_NAV_NEXT: case ElementOperator.OP_NAV_NEXT_OR_SAME: return date.plus(1, CalendarUnit.DAYS).atStartOfDay(); case ElementOperator.OP_NAV_PREVIOUS: case ElementOperator.OP_NAV_PREVIOUS_OR_SAME: return date.atStartOfDay(); default: throw new AssertionError("Unknown: " + this.mode); } }
PlainDate ls = PlainDate.of(2015, 6, 30); Moment start = ls.atStartOfDay().atUTC(); Moment end = ls.plus(1, CalendarUnit.DAYS).atStartOfDay().atUTC(); System.out.println(SI.SECONDS.between(start, end)); // 86401
// conversion from jalali to gregorian by constructed input PersianCalendar jalali = PersianCalendar.of(1394, 11, 5); // or use a safe enum instead of the month number: // PersianCalendar jalali = PersianCalendar.of(1394, PersianMonth.BAHMAN, 5); PlainDate gregorian = jalali.transform(PlainDate.class); System.out.println(gregorian); // 2016-01-25 // conversion to millis-since-unix (timezone-dependent) Moment moment1 = gregorian.atStartOfDay().inTimezone(ASIA.TEHRAN); long millisSinceUnix = TemporalType.MILLIS_SINCE_UNIX.from(moment1); System.out.println(millisSinceUnix); // 1453667400000L // conversion of millis-since-unix to jalali (timezone-dependent) Moment moment2 = TemporalType.MILLIS_SINCE_UNIX.translate(millisSinceUnix); PlainDate gregorian2 = moment2.toZonalTimestamp(ASIA.TEHRAN).toDate(); System.out.println(gregorian2.transform(PersianCalendar.class)); // AP-1394-11-05 // formatting and parsing in Farsi language using full style ChronoFormatter<PersianCalendar> f1 = ChronoFormatter.ofStyle(DisplayMode.FULL, new Locale("fa"), PersianCalendar.axis()); System.out.println(f1.format(jalali)); // ه.ش. ۱۳۹۴ بهمن ۵, دوشنبه System.out.println(f1.parse("ه.ش. ۱۳۹۴ بهمن ۵, دوشنبه")); // AP-1394-11-05 // formatting in English language using custom pattern ChronoFormatter<PersianCalendar> f2 = ChronoFormatter.ofPattern( "d. MMMM yyyy", PatternType.CLDR, Locale.ENGLISH, PersianCalendar.axis()); System.out.println(f2.format(jalali)); // 5. Bahman 1394
/** * <p>Creates a new local timestamp with this date at earliest valid time * at the begin of associated day in given timezone. </p> * * @param tzid timezone id * @return local timestamp as composition of this date and earliest valid time * @throws IllegalArgumentException if given timezone cannot be loaded * @throws UnsupportedOperationException if the underlying timezone * repository does not expose any public transition history * @see #atStartOfDay() * @see #atFirstMoment(TZID) * @since 2.2 */ /*[deutsch] * <p>Erzeugt einen lokalen Zeitstempel mit diesem Datum zur frühesten * gültigen Uhrzeit in der angegebenen Zeitzone. </p> * * @param tzid timezone id * @return local timestamp as composition of this date and earliest valid time * @throws IllegalArgumentException if given timezone cannot be loaded * @throws UnsupportedOperationException if the underlying timezone * repository does not expose any public transition history * @see #atStartOfDay() * @see #atFirstMoment(TZID) * @since 2.2 */ public PlainTimestamp atStartOfDay(TZID tzid) { return this.atStartOfDay(Timezone.of(tzid).getHistory()); }
/** * <p>Creates a new local timestamp with this date at earliest valid time * at the begin of associated day in given timezone. </p> * * @param tzid timezone id * @return local timestamp as composition of this date and earliest valid time * @throws IllegalArgumentException if given timezone cannot be loaded * @throws UnsupportedOperationException if the underlying timezone * repository does not expose any public transition history * @see #atStartOfDay() * @see #atFirstMoment(String) * @since 2.2 */ /*[deutsch] * <p>Erzeugt einen lokalen Zeitstempel mit diesem Datum zur frühesten * gültigen Uhrzeit in der angegebenen Zeitzone. </p> * * @param tzid timezone id * @return local timestamp as composition of this date and earliest valid time * @throws IllegalArgumentException if given timezone cannot be loaded * @throws UnsupportedOperationException if the underlying timezone * repository does not expose any public transition history * @since 2.2 * @see #atStartOfDay() * @see #atFirstMoment(String) * @since 2.2 */ public PlainTimestamp atStartOfDay(String tzid) { return this.atStartOfDay(Timezone.of(tzid).getHistory()); }
Date jud = TemporalType.JAVA_UTIL_DATE.from(date.atStartOfDay().atUTC()); text = this.setUpLocal().format(jud); } else if (this.type.equals(PlainTime.class)) {
t1 = d1.at(PlainTime.midnightAtEndOfDay()); } else { t1 = d1.atStartOfDay(); PlainTimestamp t2; if (this.getEnd().isOpen()) { t2 = d2.atStartOfDay(); } else { t2 = d2.at(PlainTime.midnightAtEndOfDay());