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).
Use Joda time or Java 8 Date time API. Following is the example of Java 8 API
if(language.equals("English")){
LocalDateTime now = LocalDateTime.now();
}
else{
HijrahDate hijrahDate=HijrahDate.now();
}
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?
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:
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 م
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With