ITPub博客

首页 > 应用开发 > Java > Java Date timezone problem

Java Date timezone problem

原创 Java 作者:opsc 时间:2010-03-23 14:56:02 0 删除 编辑

Be careful when you're using Date for your java application.

When you have a different timezone setting between your application client and the application server host, you may see time different with what you want.

Like:

Date dt = new Date();

It will show you a time with your local timezone, when you're wring a jsp file which need to get the current time, it will not be the server time.

Try use Calendar instead:

Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT-07:00"));

[@more@]Something tiny but really helps.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/21084389/viewspace-1032259/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-10-21

  • 博文量
    14
  • 访问量
    41573