represents a specific instant in time, with millisecond
precision.
class for converting between a Date
object and a set of integer fields such as YEAR
, MONTH
,
DAY
, HOUR
, and so on. Years are the
actual year (2001, 2004, etc), DAY_OF_MONTH is one relative, that is March
1 is a 1. MONTH is zero relative, January is 0, February is 1, etc.GregorianCalendar()
- create an object based
on the current time and dateGregorianCalendar(int year,
int month, int date, int hour,
int minute, int second)
- create an object based on the specified information used
for formatting and parsing dates in a locale-sensitive
manner. It allows for formatting (date -> text), parsing (text ->
date), and normalization.
constructors:
Pattern letter
Time component
Example output:
G
Era designator AD
y
Year 1996
;96
M
Month in year July
;Jul
;07
w
Week in year 27
W
Week in month 2
D
Day in year 189
d
Day in month 10
F
Day of week in month 2
E
Day in week Tuesday
;Tue
a
Am/pm marker PM
H
Hour in day (0-23) 0
k
Hour in day (1-24) 24
K
Hour in am/pm (0-11) 0
h
Hour in am/pm (1-12) 12
m
Minute in hour 30
s
Second in minute 55
S
Millisecond 978
z
Time zone Pacific Standard Time
;PST
;GMT-08:00
Z
Time zone -0800
Examples:
Date and Time Pattern Result "yyyy.MM.dd G 'at' HH:mm:ss z"
2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy"
Wed, Jul 4, '01
"h:mm a"
12:08 PM
"hh 'o''clock' a, zzzz"
12 o'clock PM, Pacific Daylight Time
"K:mm a, z"
0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa"
02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z"
Wed, 4 Jul 2001 12:08:56 -0700
DATE
value. To conform to SQL's definition
of DATE
, the millisecond values wrapped by a java.sql.Date
instance must be 'normalized' by setting the hours, minutes, seconds,
and milliseconds to zero in the particular time zone with which the instance
is associated.long date
) - creates a date object the
specified time.Date
value. yyyy-mm-ddjava.util.Date
class that allows the JDBC
API to identify this as an SQL TIME
value. The Time
class adds formatting and parsing operations to support the JDBC escape
syntax for time values. The date components should be set to the "zero epoch"
value of January 1, 1970 and should not be accessed.java.util.Date
that allows the JDBC
API to identify this as an SQL TIMESTAMP
value. This allows the
holding of time in terms of nanoseconds.yyyy-mm-dd hh:mm:ss.fffffffff
) to a Time
value.yyyy-mm-dd hh:mm:ss.fffffffff
).java.util.Date d = new java.util.Date();
SimpleDateFormat frm = new SimpleDateFormat("MM/dd/yyyy G hh:mm:ss aa z");
outputField.setText(frm.format(d));
GregorianCalendar cal = new GregorianCalendar(2004,2,24,12,30,3); // create a calendar date Feb 24, 2004 at 12:30:03
GregorianCalendar checkoutdate = new GregorianCalendar(); // set the date checked out to today's date and time
GregorianCalendar duedate = new GregorianCalendar(); // set due date to today's date
duedate.add(GregorianCalendar.DAY_OF_YEAR,14); // add 14 days to due date
Date due = duedate.getTime(); // due date in Date format