Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将日期时间转换为特定区域设置_Java_Android_Localization - Fatal编程技术网

Java 将日期时间转换为特定区域设置

Java 将日期时间转换为特定区域设置,java,android,localization,Java,Android,Localization,我正在尝试转换一个日期时间,它是周一4月18日22:56:10 GMT+2016年05:30 我必须将其转换为(印地语)中的区域设置hi 我正在执行以下步骤: Date time = "Mon Apr 18 22:56:10 GMT+05:30 2016"; String dateTimeFormat = "dd MMM yyyy hh:mm aa"; SimpleDateFormat sdfgmt = new SimpleDateFormat(dateTimeFormat, new Local

我正在尝试转换一个日期时间,它是
周一4月18日22:56:10 GMT+2016年05:30

我必须将其转换为(印地语)中的区域设置
hi

我正在执行以下步骤:

Date time = "Mon Apr 18 22:56:10 GMT+05:30 2016";
String dateTimeFormat = "dd MMM yyyy hh:mm aa";
SimpleDateFormat sdfgmt = new SimpleDateFormat(dateTimeFormat, new Locale("hi","IN"));
sdfgmt.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(sdfgmt.format(time));
我得到的结果是,只有一个月得到了翻译。其他数字,AM/PM字段仍然未翻译

有谁能提供同样的解决方案吗。我已经阅读了许多类似的帖子,并遵循了以下链接中的步骤:

注意:我实际上是在Android应用程序中使用上面的代码片段

提前谢谢。

以下是我的步骤

// Initial date time in String forma†
String timeOrg = "Mon Apr 18 22:56:10 GMT+05:30 2016";
// Corresponding date format
String dateTimeFormatOrg = "EEE MMM dd hh:mm:ss z yyyy";
// SimpleDateFormat using US locale to be able to parse "Mon Apr"
SimpleDateFormat sdfgmtOrg = new SimpleDateFormat(dateTimeFormatOrg, Locale.US);
// Parse the date 
Date time = sdfgmtOrg.parse(timeOrg);

// Target date format
String dateTimeFormat = "dd MMM yyyy hh:mm aa";
// SimpleDateFormat using the target locale
SimpleDateFormat sdfgmt = new SimpleDateFormat(dateTimeFormat, new Locale("hi","IN"));
// Set the Time Zone to UTC
sdfgmt.setTimeZone(TimeZone.getTimeZone("UTC"));
// Print the formatted date
System.out.println(sdfgmt.format(time))
输出:

१८ अप्रैल २०१६ ०५:२६ अपराह्न

我知道这可能不是;这不会有什么帮助,但如果可能的话,我会尽量避免使用旧的
java.util.Date
类,而使用新的
java.time.*
类。这是一个更好的API和更少的bug@布雷茨:谢谢。这个
Date time=“Mon Apr 18 22:56:10 GMT+05:30 2016”
甚至不编译我不会读印地语,但如果我正确解析原始日期,我会得到
१८ अप्रैल २०१६ ०५:२६ अपराह्न
,这是你想要的吗?@NicolasFilotto:是的,你在哪里把语言环境设置为印地语?在我的例子中,我得到的语言环境是以“hi-in”的形式输出的,仍然是一样的:(,只有一个月的时间被翻译了…,你的时区ID和默认语言环境是什么?你使用哪一版本的Java?让我们来看看。