Java日期在阿拉伯语 [英] Java date time in arabic

查看:954
本文介绍了Java日期在阿拉伯语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户选择语言是阿拉伯语,那么在春季申请中选择语言是英文时,如何获取阿拉伯语的日期?我尝试通过根据请求将默认语言环境设置为英语和阿拉伯语,但这并不能帮助我在阿拉伯语中获取日程表时间(9小时15分钟)。

解决方案

困惑的问题



您的问题令人困惑,您的评论无助于澄清。您是否想要伊斯兰历法,您需要

?如果是这样, Masud回答是正确的。



您要将日期时间的时区调整为阿拉伯地区,例如利雅得



您是否要本地化日期时间的文字表示中使用的字词,例如月和日名称?



您是否希望本地化日期时间的文本表示形式,例如日,月,年的显示顺序?



Joda-时间



我将使用Joda-Time 2.3图书馆推出一些示例代码,希望可能有所帮助。



创建 java.util.Locale ,您需要:





示例代码



  DateTime dateTimeUtc = new DateTime(DateTimeZone 。世界标准时间 ); 

DateTimeZone timeZone = DateTimeZone.forID(亚洲/利雅得);
DateTime dateTimeRiyadh = dateTimeUtc.withZone(timeZone);

java.util.Locale locale = new Locale(ar,SA); //(语言代码,国家代码);
DateTimeFormatter formatter = DateTimeFormat.forStyle(FF).withLocale(locale).withZone(timeZone);
String output = formatter.print(dateTimeUtc);

转储到控制台...

  System.out.println(dateTimeUtc:+ dateTimeUtc); 
System.out.println(dateTimeRiyadh:+ dateTimeRiyadh);
System.out.println(output:+ output);

运行时

  dateTimeUtc:2014-02-16T09:52:33.901Z 
dateTimeRiyadh:2014-02-16T12:52:33.901 + 03:00
输出: 16فبراير,2014 AST 12:52:33م


How to get arabic date when the user selected language is Arabic and date in english format when selected language is english in spring application ? I tried by setting the default locale to english and arabic based on the request but this doesn't help me in getting calendar api time in arabic for (9 hours 15 mins).

解决方案

Confused Question

Your question is confusing, and your comment did not help to clarify.

Did you want an Islamic calendar? If so, the answer by Masud is correct.

Did you want to adjust the time zone of the date-time to an Arab location such as Riyadh?

Did you want to localize the words used in the textual representation of a date-time, such as month and day name?

Did you want to localize the format of textual representation of a date-time, such as the order of presentation of day, month, year?

Joda-Time

I'll just spin out a bit of example code using the Joda-Time 2.3 library, hoping it might help.

To create a java.util.Locale, you need:

Example Code

DateTime dateTimeUtc = new DateTime( DateTimeZone.UTC );

DateTimeZone timeZone = DateTimeZone.forID( "Asia/Riyadh" );
DateTime dateTimeRiyadh = dateTimeUtc.withZone( timeZone );

java.util.Locale locale = new Locale( "ar", "SA" ); // ( language code, country code );
DateTimeFormatter formatter = DateTimeFormat.forStyle( "FF" ).withLocale( locale ).withZone( timeZone );
String output = formatter.print( dateTimeUtc );

Dump to console…

System.out.println( "dateTimeUtc: " + dateTimeUtc );
System.out.println( "dateTimeRiyadh: " + dateTimeRiyadh );
System.out.println( "output: " + output );

When run…

dateTimeUtc: 2014-02-16T09:52:33.901Z
dateTimeRiyadh: 2014-02-16T12:52:33.901+03:00
output: 16 فبراير, 2014 AST 12:52:33 م

这篇关于Java日期在阿拉伯语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆