TL; ড
জেএসআর 310 এর আধুনিক জাভা.টাইম ক্লাসগুলি 12-ঘন্টার হার্ড-কোডিং এবং এএম / প্রধানমন্ত্রী না হয়ে স্বয়ংক্রিয়ভাবে স্থানীয় পাঠ্য তৈরি করতে দিন।
LocalTime // Represent a time-of-day, without date, without time zone or offset-from-UTC.
.now( // Capture the current time-of-day as seen in a particular time zone.
ZoneId.of( "Africa/Casablanca" )
) // Returns a `LocalTime` object.
.format( // Generate text representing the value in our `LocalTime` object.
DateTimeFormatter // Class responsible for generating text representing the value of a java.time object.
.ofLocalizedTime( // Automatically localize the text being generated.
FormatStyle.SHORT // Specify how long or abbreviated the generated text should be.
) // Returns a `DateTimeFormatter` object.
.withLocale( Locale.US ) // Specifies a particular locale for the `DateTimeFormatter` rather than rely on the JVM’s current default locale. Returns another separate `DateTimeFormatter` object rather than altering the first, per immutable objects pattern.
) // Returns a `String` object.
10:31 AM
স্বয়ংক্রিয়ভাবে স্থানীয়করণ ize
এএম / প্রধানমন্ত্রীর সাথে 12-ঘন্টা ঘড়ির উপর জোর দেওয়ার পরিবর্তে আপনি জাভা.টাইম আপনার জন্য স্বয়ংক্রিয়ভাবে স্থানীয়করণ করতে চাইতে পারেন । কলDateTimeFormatter.ofLocalizedTime
।
স্থানীয়করণের জন্য, নির্দিষ্ট করুন:
FormatStyle
স্ট্রিংটি কত দীর্ঘ বা সংক্ষিপ্ত হওয়া উচিত তা নির্ধারণ করতে।
Locale
নির্ধারণ:
- মানুষের ভাষা দিনের নামের অনুবাদ, মাসের নাম, এবং এই ধরনের জন্য।
- সাংস্কৃতিক নিয়ম সংক্ষেপ, ক্যাপিটালাইজেশন, যতিচিহ্ন থাকতে পারে, বিভাজক এবং এই ধরনের সমস্যা সিদ্ধান্ত।
একটি নির্দিষ্ট সময় অঞ্চলে দেখা হিসাবে আমরা এখানে বর্তমান সময়ের বর্তমান সময় পাই। তারপরে আমরা সেই সময়ের প্রতিনিধিত্ব করার জন্য পাঠ্য উত্পন্ন করি। আমরা কানাডা সংস্কৃতিতে ফরাসী ভাষায় এবং পরে মার্কিন সংস্কৃতিতে ইংরেজি ভাষাতে স্থানীয়করণ করি।
ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;
LocalTime localTime = LocalTime.now( z ) ;
// Québec
Locale locale_fr_CA = Locale.CANADA_FRENCH ; // Or `Locale.US`, and so on.
DateTimeFormatter formatterQuébec = DateTimeFormatter.ofLocalizedTime( FormatStyle.SHORT ).withLocale( locale_fr_CA ) ;
String outputQuébec = localTime.format( formatterQuébec ) ;
System.out.println( outputQuébec ) ;
// US
Locale locale_en_US = Locale.US ;
DateTimeFormatter formatterUS = DateTimeFormatter.ofLocalizedTime( FormatStyle.SHORT ).withLocale( locale_en_US ) ;
String outputUS = localTime.format( formatterUS ) ;
System.out.println( outputUS ) ;
IdeOne.com এ এই কোডটি সরাসরি চালিত দেখুন ।
10 এইচ 31
10:31 AM
SimpleDateFormat formatDate = new SimpleDateFormat("hh:mm a");