i m creating date format like this :
SimpleDateFormat sdf =new SimpleDateFormat("MMM d, EEE, h:mm a");
i need a new line between date, month and time something like this
thus ,sep 6
4:25pm
so i made the following changes :
SimpleDateFormat sdf =new SimpleDateFormat("MMM d, EEE,"+"\n"+" h:mm a");
it did not give me anything just it created it in one line like this :
thus ,sep 6 4:25pm
so i took format object like this
SimpleDateFormat sdf =new SimpleDateFormat("MMM d, EEE,");
SimpleDateFormat sdf1 =new SimpleDateFormat(" h:mm a");
and did this :
sdf.format(calendar.getTime())+"\n"+sdf1.format(calendar.getTime())
but it again gives the same result
thus ,sep 6 4:25pm
calendar is a Calendar object.Any help will be appreciated!!
I see from one of your comments that your original solution actually works, but I had the same question when I came here, so let me add an answer to this question. (My formatting is a little different than yours.)
Date date = new Date(unixMilliseconds);
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy\nh:mma");
String formattedDate = sdf.format(date);
The \n
in MMM d, yyyy\nh:mma
works because neither the \
nor the n
are interpreted by SimpleDateFormat
(see documentation) and thus are passed on to the Java String. If they did have special meaning you could have used single quotes: MMM d, yyyy'\n'h:mma
(which also works).
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