Reputation: 4464
Quick question, SimpleDateFormat
is not performing as I would expect. I am looking to get a date string that look like Thursday 29 November 13:43
.
Here is my format:
Calendar c = Calendar.getInstance();
_clockDateFormat = new SimpleDateFormat("cccc dd MMMM kk:mm");
_clockDateFormat.format(c.getTime());
Here is the output:
5 29 11 13:43
What am I doing wrong?
Upvotes: 3
Views: 2291
Reputation: 66637
Instead of c
use E
:
Calendar c = Calendar.getInstance();
SimpleDateFormat _clockDateFormat = new SimpleDateFormat("EEEE dd MMMM kk:mm");
System.out.println(_clockDateFormat.format(c.getTime()));
output:
Thursday 29 November 14:05
See the documentation for more info.
Upvotes: 3
Reputation: 4464
Turns out the device I am working with doesn't have a default locale when it gets here from the factory. As a workaround I used the Locale
specific overload for SimpleDateFormat
:
_clockDateFormat = new SimpleDateFormat("EEEE dd MMMM HH:mm", Locale.US);
Upvotes: 2
Reputation: 862
In my pc I have tried the following
Calendar c = Calendar.getInstance();
SimpleDateFormat _clockDateFormat = new SimpleDateFormat("yyyy dd MMMM kk:mm");
_clockDateFormat.format(c.getTime());
System.out.println(_clockDateFormat.format(c.getTime()));
if i use 'cccc' in simpledateformat it gives an error!!!
Upvotes: 1
Reputation: 328568
Have you tried:
_clockDateFormat = new SimpleDateFormat("EEEE dd MMMM kk:mm");
Upvotes: 1