How to display AM / PM field in Japanese using SimpleDateFormat in Java?

I want to display the time in the following format for Japanese "01:00 午後"

My current source code is as follows

Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
System.out.println("Start Time "+SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM,Locale.JAPANESE).format(date));

I get the following conclusion Start time 7:09:37

PS: I also tried to set the time format to "K: mm a" and "H: mm a". Both of them did not work.

+4
source share
1 answer

You have created an object SimpleDateFormatbut are not using it. Provide Localethis class and see the result.

Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy a", Locale.JAPANESE);
System.out.println("Start Time "+ sdf.format(date));

Exit: Start Time 10/16/2015 午後

H:mm a DateFormat MM/dd/yyyy a, , Start Time 13:01 午後

, Date Formats Java.

0

Source: https://habr.com/ru/post/1611892/


All Articles