The TimeZone class has a getOffset() method that will return the offset for a specified date. For example to get the timezone offset for today you would use the following:
Date today = new Date();
TimeZone tz = TimeZone.getDefault();
long offset = tz.getOffset(today);
written by objects
\\ tags: calendar, date, timezone
The Calendar class can be used to do a variety of date arithmetic
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.HOUR, numberOfHours);
date = cal.getTime();
written by objects
\\ tags: calendar, date
Either use the format() method of the SimpleDateFormat class, or the (static) format() method of the String class.
DateFormat dateFormat = new SimpleDateFormat("hhmmddMMyy");
Date today = new Date();
String formatted = dateFormat.format(today);
String formatted2 =
String.format("%<tH%<tM%<tS%tY%<tm%<td", today);
written by objects
\\ tags: convert, date, format, string
Recent Comments