Here this last_checked_datetime is my date stored in database which is in utc format,
Timestamp ts1=rs9.getTimestamp("last_checked_datetime");
java.sql.Date last_chk=new java.sql.Date(ts1.getTime());
java.util.Date time=new java.util.Date(last_chk.getTime());
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("HH:mm:ss");
String old_time=sdf.format(time);
When I call this Date() it was print EST time
String new_time=sdf.format(new Date());
Date date1 = sdf.parse(old_time);
Date date2 = sdf.parse(new_time);
I want difference of these two but date1 take utc time and date2 take est time which cause a barrier in my code? Please suggest
尝试将默认时区设置为:
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Take a look at org.joda.time.DateTime
This allows you to control what timezone you want the date to be in.
For example:
DateTime.now().withZone(DateTimeZone.UTC).toDate()
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("EST"));
//change the timezone
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.