Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class TimeMath

  1. Object
  2. TimeMath

Calendar arithmetic on epoch milliseconds in a time zone.

The scheduling model keeps every instant as epoch milliseconds, because a view compares and subtracts them for every item it paints. These are the few places where an instant has to become a calendar day and back, and they go through java.time so a day that is 23 or 25 hours long is handled by the zone rules and not by adding 24 * 60 * 60 * 1000.

Fields

public static final long MINUTE = 60000LMilliseconds in a minute.
public static final long HOUR = 3600000LMilliseconds in an hour.
public static final long DAY = 86400000LMilliseconds in a day that has no zone transition in it.
public static final int MINUTES_PER_DAY = 1440Minutes in a day.

Methods

public static long epochDay(long millis, ZoneId zone)The day millis falls on in zone, as a count of days since 1970-01-01.
public static long startOfEpochDay(long epochDay, ZoneId zone)The instant the day epochDay starts at in zone.
public static long startOfDay(long millis, ZoneId zone)The start of the day millis falls on.
public static long at(long epochDay, int minuteOfDay, ZoneId zone)The instant of a wall-clock minute on a day.
public static int minuteOfDay(long millis, ZoneId zone)The wall-clock minute of the day at millis.
public static int dayOfWeek(long epochDay)The ISO day of the week of a day: 1 is Monday, 7 is Sunday.
public static long startOfWeek(long epochDay, int firstDayOfWeek)The first day of the week epochDay is in, when weeks start on firstDayOfWeek (ISO, 1 is Monday).
public static long startOfMonth(long epochDay)The first day of the month epochDay is in.
public static long plusMonths(long epochDay, int months)The first day of the month months after the one epochDay is in.

Inherited methods

Field details

MINUTE

public static final long MINUTE = 60000L
Milliseconds in a minute.

HOUR

public static final long HOUR = 3600000L
Milliseconds in an hour.

DAY

public static final long DAY = 86400000L
Milliseconds in a day that has no zone transition in it.

MINUTES_PER_DAY

public static final int MINUTES_PER_DAY = 1440
Minutes in a day.

Method details

epochDay

public static long epochDay(long millis, ZoneId zone)
The day millis falls on in zone, as a count of days since 1970-01-01.

startOfEpochDay

public static long startOfEpochDay(long epochDay, ZoneId zone)
The instant the day epochDay starts at in zone.

startOfDay

public static long startOfDay(long millis, ZoneId zone)
The start of the day millis falls on.

at

public static long at(long epochDay, int minuteOfDay, ZoneId zone)
The instant of a wall-clock minute on a day. minuteOfDay may be 1440, which is the start of the following day.

minuteOfDay

public static int minuteOfDay(long millis, ZoneId zone)
The wall-clock minute of the day at millis.

dayOfWeek

public static int dayOfWeek(long epochDay)
The ISO day of the week of a day: 1 is Monday, 7 is Sunday.

startOfWeek

public static long startOfWeek(long epochDay, int firstDayOfWeek)
The first day of the week epochDay is in, when weeks start on firstDayOfWeek (ISO, 1 is Monday).

startOfMonth

public static long startOfMonth(long epochDay)
The first day of the month epochDay is in.

plusMonths

public static long plusMonths(long epochDay, int months)
The first day of the month months after the one epochDay is in.