我已经在openshift(免费版)上部署了一个Web应用程序,并且一直在努力修复时区而没有运气。我的时区“亚洲/科伦坡”。我怎样才能做到这一点?
我的应用程序托管在Apache Tomcat 7服务器中。
// gives me current date from server time zone
java.util.Date date = new Date();
// However for now I manage to fix the issue with below code
// without having to change it from server side.
public static Date getNormalizedDate() {
Calendar today = Calendar.getInstance(TimeZone.getTimeZone("Asia/Colombo"));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, today.get(Calendar.DATE));
cal.set(Calendar.MONTH, today.get(Calendar.MONTH));
cal.set(Calendar.MONTH, today.get(Calendar.MONTH));
cal.set(Calendar.HOUR_OF_DAY, today.get(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, today.get(Calendar.MINUTE));
cal.set(Calendar.SECOND, today.get(Calendar.SECOND));
return (cal.getTime());
}