java 阿拉伯语,Java日期在阿拉伯语

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 م

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值