【发布时间】:2010-11-21 06:41:33
【问题描述】:
我的应用托管在伦敦服务器上。我在西班牙马德里。所以时区是-2小时。
如何使用我的时区获取当前日期/时间。
Date curr_date = new Date(System.currentTimeMillis());
例如
Date curr_date = new Date(System.currentTimeMillis("MAD_TIMEZONE"));
与Joda-Time
DateTimeZone zone = DateTimeZone.forID("Europe/Madrid");
DateTime dt = new DateTime(zone);
int day = dt.getDayOfMonth();
int year = dt.getYear();
int month = dt.getMonthOfYear();
int hours = dt.getHourOfDay();
int minutes = dt.getMinuteOfHour();
【问题讨论】:
-
例如代码使用 Joda-Time 在时区之间进行转换,请参阅问题my answerJava Convert GMT/UTC to Local time doesn't work as expected