本文介绍了Java如何在IST中打印时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在可以获取时间和时区。 ,但始终以

I am able to get the time as well as timezone currently. but it always printed in

Wed May 23 11:01:08 GMT+05:30 2012

在TimeZone上,我正在获得 GMT + 05:30 。而不是我想打印 IST

As TimeZone i am getting GMT+05:30. instead of this i want to print IST

我尝试过

 SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");

但我仍然得到 GMT + 05:30

TimeZone.getDefault().getDisplayName(true, TimeZone.SHORT); is also givine me GMT+05:30

我尝试了多种方法,但没有得到欲望输出。我曾经使用 Calender ,但仍然无法打印 IST

There are various things i tried but did not get desire ouput. I have used Calender but still unable to print IST .

有人可以让我知道如何在时间上打印 IST (甚至我也不想打印印度标准时间

Can anyone please let me know how to print IST in Time (even i dont want to print Indian standard time)

推荐答案

您尚未显示使用实际位置> SimpleDateFormat 。这是一个简短但完整的示例,其中确实显示了IST:

You haven't shown where you're actually using the SimpleDateFormat. Here's a short but complete example which does show IST:

import java.text.*;
import java.util.*;

class Test {
    public static void main(String[] args) {
        SimpleDateFormat sd = new SimpleDateFormat(
            "yyyy.MM.dd G 'at' HH:mm:ss z");
        Date date = new Date();
        // TODO: Avoid using the abbreviations when fetching time zones.
        // Use the full Olson zone ID instead.
        sd.setTimeZone(TimeZone.getTimeZone("IST"));
        System.out.println(sd.format(date));
   }
}

我的机器上的输出:

2012.05.23 AD at 11:18:08 IST

请注意,如果 TimeZone.getDefault()没有显示 IST,则问题可能是:

Note that if TimeZone.getDefault() isn't showing "IST" then the issue may be:


  • 系统无法真正识别您的系统时区

  • 您的Java安装没有有关以下内容的完整时区信息i18n

您正在使用哪个Java版本以及在哪个平台上使用?

Which version of Java are you using, and on what platform?

这篇关于Java如何在IST中打印时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 16:14