@MinDoc(copyright="Copyright 2000 - 2009, 2016 A. Weinert", author="Albrecht Weinert", version="V.56", lastModified="28.06.2021", usage="import TimeHelper to your classes or\n\n java de.frame4j.time.TimeHelper [options] [time [time .. [loop]", purpose="common time and date utilities and constants, parser") public final class TimeHelper extends Object implements ComVar
ComVar
ComVar.Impl
Modifier and Type | Field and Description |
---|---|
static Action |
ACTION_TZ0
Action for time zone offset 0 , UTC.
|
static int |
DAYSin4YEARS
Days in four years (implying one of it being a leap year).
|
static Action[] |
RATE_CHOOSE
Action list for duration or rates.
|
static Action[] |
TIME_CHOOSE
Action list for date and time of day.
|
AUTHOR, BLANK_STRING, cons, CONSOL_ENCODING, COPYRIGHT, D, D_NaN, D_NegInf, D_PosInf, EMPTY_INT_A, EMPTY_STRING, FILE_ENCODING, FRW_CLLD, FS, FSS, H, hasCons, HOST_IP, HOST_IPv4, HOST_NAME, INIT_ERROR, JAR_ENCODING, JH, JOB_DONE_OK, JRL, LOG_OUT_ERROR, M, MAIN_THREAD_EXC, NO_BYTES, NO_CLASSES, NO_DOUBLES, NO_OBJECTS, NO_PARS_ERROR, NO_STRINGS, NOT_WINDOWS, ON_PI, ONE_DAY, ONE_HOUR, ONE_LEAP_YEAR, ONE_MINUTE, ONE_SECOND, ONE_WEEK, ONE_YEAR, OS, PROG_NAME, PROG_SHORT, PS, RUNTIME, S, SHY, UD, UL, UL_UR_da, UR
Modifier and Type | Method and Description |
---|---|
static StringBuilder |
appendDuration(StringBuilder bastel,
long dur)
Format a duration or rate.
|
static int |
daysSince1Mrz68(int d,
int m,
int j)
Calculate the days since 1 March 1968 .
|
static String |
format(CharSequence form,
Instant inst)
Format date and time of day freely with default time zone.
|
static String |
format(CharSequence form,
Instant inst,
ZoneId zone)
Format date and time of day freely with explicit time zone.
|
static String |
format(CharSequence form,
long time)
Format date and time of day freely with default time zone.
|
static String |
format(CharSequence form,
long time,
ZoneId zone)
Format date and time of day freely with explicit time zone.
|
static String |
format(CharSequence form,
Object time)
Format date and time of day freely with default time zone.
|
static String |
format(CharSequence form,
ZonedDateTime zoDtTi)
Format date and time of day freely (PHP format string).
|
static String |
format(CharSequence form,
ZonedDateTime zoDtTi,
AppLangMap alm)
Format date and time of day freely and with explicit language.
|
static String |
formatDIN(long time)
Format date and time of day in the Form 08.01.2001 10:43:59.
|
static String |
formatDIN(ZonedDateTime zoDtTi)
Format date and time of day in the Form 08.01.2001 10:43:59.
|
static String |
formatGMT(ZonedDateTime zoDtTi)
Format date and time of day as 8 Jan 2001 10:43:59 GMT.
|
static String |
formatISO(Instant inst,
ZoneId zone)
Format date and time of day like 2009-02-02T11:00:00.000Z.
|
static String |
formatISO(ZonedDateTime zoDtTi)
Format date and time of day like 2009-02-02T11:00:00.000Z .
|
static StringBuilder |
formatISO(ZonedDateTime zoDtTi,
StringBuilder bastel)
Format date and time of day like 2009-02-02T11:00:00.000Z .
|
static String |
formatRFC(Instant inst,
ZoneId zone)
Format date and time of day like Mon, 11 Mar 2002 14:09:45 +0100.
|
static String |
formatRFC(ZonedDateTime zoDtTi)
Format date and time of day like Mon, 11 Mar 2002 14:09:45 +0100 (GMT).
|
static StringBuilder |
formatRFC(ZonedDateTime zoDtTi,
StringBuilder bastel)
Format date and time of day like Mon, 11 Mar 2002 14:09:45 +0100 .
|
static String |
formatSQL(long time)
Formatting of date and time as 2006-08-14 23:21:59 .
|
static String |
formatSQL(ZonedDateTime zoDtTi)
Formatting of date and time as 2006-08-14 23:21:59 .
|
static StringBuilder |
formHH_MMSS(ZonedDateTime zoDtTi,
StringBuilder bastel)
Format the time part as hh:mm:ss.
|
static boolean |
instanceOfTime(Object time)
Is an object of a time type.
|
static boolean |
isLeapYear(int y)
Leap year.
|
static long |
javaTimetoMS(long javaTime)
Transform Java time (long, ms to Microsoft time stamp (long, ns).
|
static void |
main(String[] args)
Display some info about class, time zones, explore the parser etc.
|
static long |
msToJavaTime(long msTimeStamp)
Transform Microsoft time stamp (long, ns) to Java time (long, ms).
|
static long |
parse(CharSequence time)
Get / parse a time from String representation.
|
static long |
parse(CharSequence time,
boolean endDay)
Get / parse a time from String representation.
|
static long |
parseDuration(CharSequence rate)
Parsing a duration (or period).
|
static int |
weekInYear(int dayInYear,
int dayOfWeek)
Number of week.
|
public static final int DAYSin4YEARS
1461
public static final Action[] RATE_CHOOSE
parseDuration(CharSequence)
public static final Action ACTION_TZ0
public static final Action[] TIME_CHOOSE
parse(CharSequence)
,
main(String[])
public static final StringBuilder formHH_MMSS(ZonedDateTime zoDtTi, StringBuilder bastel)
zoDtTi
- the time to formatbastel
- where to append the formatted time;
if null an empty StrinBuuilder is suppliedpublic static String formatSQL(long time)
time
defined by the parameter in
in SQL format.
It knows nothing about time zones or so, but it is sortable as
String.time
- ms since 1.1.1970public static String formatSQL(ZonedDateTime zoDtTi)
time
defined by the parameter in
in SQL format.
It knows nothing about time zones or so, but it is sortable as
String.zoDtTi
- the time to formatpublic static String formatDIN(ZonedDateTime zoDtTi)
format("j.m.Y H:i:s", zoDtTi)
.zoDtTi
- the time to formatpublic static String formatDIN(long time)
DEF_ZONE
).time
- the time to format as ms from 1.1.1970public static String format(CharSequence form, ZonedDateTime zoDtTi)
"D, d.m.Y, H:i:s (l)"
.Object.toString()
) is used.AppLangMap
. English and German must always be available
and (hopefully) the platform language.form
- The format String.TextHelper.twoDigit(int)
,
formatDIN(ZonedDateTime)
,
AppLangMap
public static String format(CharSequence form, long time)
DEF_ZONE
, like
format(CharSequence, ZonedDateTime)
.form
- Format; see format(CharSequence, ZonedDateTime)
time
- ms since 1.1.1970public static String format(CharSequence form, Instant inst)
DEF_ZONE
, like
format(CharSequence, ZonedDateTime)
.form
- Format; see format(CharSequence, ZonedDateTime)
inst
- the timepublic static String format(CharSequence form, Object time)
DEF_ZONE
, like
format(CharSequence, ZonedDateTime)
.form
- Format; see format(CharSequence, ZonedDateTime)
time
- the time if instanceOfTime
empty String
public static boolean instanceOfTime(Object time)
Long
, Instant
, ZonedDateTime
, Date
.
time
- the object to be type checkedformat(CharSequence, Object)
public static String format(CharSequence form, long time, ZoneId zone)
format(CharSequence, ZonedDateTime)
.form
- Format; see format(CharSequence, ZonedDateTime)
time
- ms since 1.1.1970zone
- the time zone to be used; null will be
DEF_ZONE
public static String format(CharSequence form, Instant inst, ZoneId zone)
format(CharSequence, ZonedDateTime)
.form
- Format; see format(CharSequence, ZonedDateTime)
inst
- the timezone
- the time zone to be used; null will be
DEF_ZONE
public static String format(CharSequence form, ZonedDateTime zoDtTi, AppLangMap alm)
format(CharSequence, ZonedDateTime)
.form
- Format; see format(CharSequence, ZonedDateTime)
alm
- explicit language (null: default)public static StringBuilder formatRFC(ZonedDateTime zoDtTi, StringBuilder bastel)
TextHelper.twoDigit(int)
public static String formatRFC(ZonedDateTime zoDtTi)
TextHelper.twoDigit(int)
public static String formatRFC(Instant inst, ZoneId zone)
zone
- the time zone; null will be
CET_ZONE
public static StringBuilder formatISO(ZonedDateTime zoDtTi, StringBuilder bastel)
TextHelper.twoDigit(int)
public static String formatISO(ZonedDateTime zoDtTi)
TextHelper.twoDigit(int)
public static String formatISO(Instant inst, ZoneId zone)
zone
- the time zone; null will
be UTC_ZONE
public static String formatGMT(ZonedDateTime zoDtTi)
TextHelper.twoDigit(int)
public static int daysSince1Mrz68(int d, int m, int j)
d
- day in month, 1 .. max, but not restrictedm
- Month, 1..12, (other values are illegal and default to March of
year j or year j-1)j
- full year like 1871, 1953, 1998, 2009, ...)public static int weekInYear(int dayInYear, int dayOfWeek)
dayInYear
- the day within the year; 1..365|366: Jan1st..Dec31stdayOfWeek
- the day in the week of dayInYear;
0..6: Monday..Saturday, all else: Sundaypublic static long msToJavaTime(long msTimeStamp)
javaTimetoMS(long)
public static long javaTimetoMS(long javaTime)
msToJavaTime(long)
public static boolean isLeapYear(int y)
public static long parse(CharSequence time) throws IllegalArgumentException
parse(CharSequence)
and parse(CharSequence, boolean)
understands a big variety of (syntactically) different formats. Likewise
time zone offsets are understood in a variety of forms.
The parsed formats include those usual in (North-) America, Europe and
Germany, as well as some Internet and operating system formats as well as
those usual in version control systems SVN and before CVS; see
SVNkeys
).main(String[])
) can be used to explore the
time parser.de.frame4j.utils.TimeHelper
) shows all
understood time keywords of Frame4J's installed version.parse(time, false)
.main(String[])
.time
- the string to be interpreted as a indication of timeIllegalArgumentException
- if time can't be parsed.Action
,
TextHelper
public static long parse(CharSequence time, boolean endDay) throws IllegalArgumentException
parse(CharSequence)
with the extra possibility to specify the end of the day (near midnight)
as default if no time of day is given.endDay
- true: no time of day in time
defaults to 23:59:59.999time
- the string to be interpreted as a indication of timeIllegalArgumentException
- if time can't be parsed.Action.selectedBy(CharSequence, boolean)
public static long parseDuration(CharSequence rate) throws IllegalArgumentException
Long
.decode()
.rate
- the duration or rateDuration
. Handling in the
sense of Period
may require DST and leap second
considerations by the user.IllegalArgumentException
- if syntax problems.public static StringBuilder appendDuration(StringBuilder bastel, long dur)
appendDuration(StringBuilder, long)
is not understood by the
parsing method parseDuration(CharSequence)
.bastel
- the StringBuilder to append to. If null, it will be
generated with starting capacity 56.dur
- duration or rate to format in mspublic static void main(String[] args)
args
- date / time string to parse and redisplayparse(CharSequence)