I want to insert the word 'at' in a SimpleDateFormat
so a date would look like:
Wed, 26 May 2010 at 11:17am
I'm able to make it appear without the at, like this
Wed, 26 May 2010 11:17am
by using
SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy hh:mma");
How can I insert the word "at"?
DateTimeFormatter is a replacement for the old SimpleDateFormat that is thread-safe and provides additional functionality.
Class SimpleDateFormat. SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.
The java SimpleDateFormat allows construction of arbitrary non-localized formats. The java DateFormat allows construction of three localized formats each for dates and times, via its factory methods.
Creating SimpleDateFormat instance String pattern = "MM-dd-yyyy"; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); In the example above the String pattern is the pattern which will be used to format a date and the output will be generated in that pattern as “MM-dd-yyyy”.
You can escape literals using single quotes.
SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy 'at' hh:mma");
This will output Wed, 26 May 2010 at 11:17am
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