Package org.kissweb
Class DateTime
java.lang.Object
org.kissweb.DateTime
Class dealing with dates with times.
-
Constructor Summary
ConstructorDescriptionDateTime
(int dt, int time) Create a DateTime object from a date (YYYYMMDD) and time (HHMM)Create a DateTime object from a date (YYYYMMDD) and time (HHMM) in the specified time zone.DateTime
(long millisecs) Create a DateTime object from the number of milliseconds since 1970 (Epoch).Create a DateTime object from a ZonedDateTime objectCreate a DateTime from a Date object.Initialize a new DateTime from a GregorianCalendar -
Method Summary
Modifier and TypeMethodDescriptionaddDays
(int days) Add days to a DateTime object.changeTimeZone
(String timeZoneId) Changes the time zone associated with this DateTime object to the specified time zone and returns the modified DateTime object.static String
Return the current date and time as a string mm/dd/yyyy hh:mm AM/PMstatic String
currentDateTimeFormatted
(String dateFormat) Returns a string representing the current date and/or time with a specified format.static String
currentDateTimeFormatted
(String dateFormat, String timeZone) Returns a string representing the current date and/or time with a specified format and within a specified timezone.static String
Return the current date and time as a string mm/dd/yyyy hh:mm AM/PM cSTformat()
Return the current date formatted as mm/dd/yyyy hh:mm AM/PMstatic String
format
(ZonedDateTime date) Format a date passed into a string mm/dd/yyyy hh:mm AM/PM.static String
format
(ZonedDateTime date, String fmt) Format a date passed into a string according to a format specification.static String
format
(ZonedDateTime dateTime, String fmt, String timeZoneId) Format a ZonedDateTime into a string using the given format string.static String
Format a date passed into a string mm/dd/yyyy hh:mm AM/PMstatic String
Format a date passed into a string formatted as determined byfmt
static String
Format a date passed into a string according to a format specification.static String
Format a date passed into a string mm/dd/yyyy hh:mm AM/PM xSTgetDate()
Get a Date representation of the DateTime object.int
getDay()
Return the day of the monthint
getHour()
Return the hour portion of a DateTimeint
Get date in an int format YYYYMMDDint
Return an integer representation of the date portion.long
Returns number of milliseconds since 1970 UTC.int
Return the minute portion of a DateTimeint
getMonth()
Return the month portion of a DateTimelong
Returns number of seconds since 1970 UTC.int
getYear()
Get the year portion of a DateTimeReturn the ZoneDateTime objectstatic void
static DateTime
now()
Create a new DateTime object that represents the current date/time.static DateTime
Create a new DateTime object that represents the current date/time in the specified time zone.
-
Constructor Details
-
DateTime
Create a DateTime object from a ZonedDateTime object- Parameters:
dt
-
-
DateTime
public DateTime(long millisecs) Create a DateTime object from the number of milliseconds since 1970 (Epoch).- Parameters:
millisecs
-
-
DateTime
public DateTime(int dt, int time) Create a DateTime object from a date (YYYYMMDD) and time (HHMM)- Parameters:
dt
- YYYYMMDDtime
- HHMM
-
DateTime
Create a DateTime object from a date (YYYYMMDD) and time (HHMM) in the specified time zone.- Parameters:
dt
- YYYYMMDDtime
- HHMMtimeZoneId
-
-
DateTime
Create a DateTime from a Date object.- Parameters:
dt
-
-
DateTime
Initialize a new DateTime from a GregorianCalendar- Parameters:
dt
-
-
-
Method Details
-
now
Create a new DateTime object that represents the current date/time.- Returns:
-
now
Create a new DateTime object that represents the current date/time in the specified time zone.- Parameters:
timeZoneId
- The time zone ID to use. Examples include "America/New_York", "America/Chicago", "Europe/London", etc.- Returns:
-
changeTimeZone
Changes the time zone associated with this DateTime object to the specified time zone and returns the modified DateTime object.
The date and time remain the same, but the time zone is changed to the new one.- Parameters:
timeZoneId
- The ID of the new time zone. Examples include "America/New_York", "America/Chicago", "Europe/London", etc.- Returns:
- This DateTime object, now with the new time zone.
-
getYear
public int getYear()Get the year portion of a DateTime- Returns:
- YYYY
-
getMonth
public int getMonth()Return the month portion of a DateTime- Returns:
- 1-12
-
getDay
public int getDay()Return the day of the month- Returns:
- (1-31)
-
getHour
public int getHour()Return the hour portion of a DateTime- Returns:
- (0-23)
-
getMinute
public int getMinute()Return the minute portion of a DateTime- Returns:
- (0-59)
-
getDate
Get a Date representation of the DateTime object.- Returns:
-
getIntDate
public int getIntDate()Get date in an int format YYYYMMDD- Returns:
-
getIntTime
public int getIntTime()Return an integer representation of the date portion.- Returns:
- HHMM
-
getZonedDateTime
Return the ZoneDateTime object- Returns:
-
format
Return the current date formatted as mm/dd/yyyy hh:mm AM/PM- Returns:
-
currentDateTimeFormatted
Return the current date and time as a string mm/dd/yyyy hh:mm AM/PM- Returns:
-
currentDateTimeFormattedTZ
Return the current date and time as a string mm/dd/yyyy hh:mm AM/PM cST- Returns:
-
format
Format a date passed into a string mm/dd/yyyy hh:mm AM/PM- Parameters:
date
-- Returns:
-
format
Format a date passed into a string mm/dd/yyyy hh:mm AM/PM.- Parameters:
date
- The date to format.- Returns:
- The formatted string.
-
format
Format a date passed into a string according to a format specification.- Parameters:
date
- The date to format.fmt
- The format string.- Returns:
- The formatted string.
-
format
Format a date passed into a string according to a format specification.- Parameters:
date
- The date to format.fmt
- The format string.timeZoneId
- The ID of the time zone to use when formatting the date. If not null or empty, the time zone is set to that zone before formatting.- Returns:
- The formatted string.
-
format
Format a ZonedDateTime into a string using the given format string. IftimeZoneId
is not null or empty, the time zone is set to that zone before formatting.- Parameters:
dateTime
- The ZonedDateTime to formatfmt
- The format stringtimeZoneId
- The time zone ID to use, if not null or empty- Returns:
- The formatted string
-
format
Format a date passed into a string formatted as determined byfmt
- Parameters:
date
-fmt
-- Returns:
- See Also:
-
formatTZ
Format a date passed into a string mm/dd/yyyy hh:mm AM/PM xST- Parameters:
date
-- Returns:
-
currentDateTimeFormatted
Returns a string representing the current date and/or time with a specified format and within a specified timezone.- Parameters:
dateFormat
-timeZone
-- Returns:
- See Also:
-
currentDateTimeFormatted
Returns a string representing the current date and/or time with a specified format.- Parameters:
dateFormat
-- Returns:
- See Also:
-
getMilliseconds
public long getMilliseconds()Returns number of milliseconds since 1970 UTC.- Returns:
-
getSeconds
public long getSeconds()Returns number of seconds since 1970 UTC.- Returns:
-
addDays
Add days to a DateTime object.- Parameters:
days
- the number of days to add - can be negative- Returns:
-
main
-