This content has been marked as final. Show 5 replies
What? Are you saying that you have a string that's exactly "YYYYMMDDHHMMSS", and you want to use it as a date format? Then just use the SimpleDateFormat constructor that takes a String as an argument.
If you're saying that you have that string, but you want to know if that's the correct format to use...then you should read the SimpleDateFormat docs to see if it will do what you want it to do. (My guess is, no -- is "MM" supposed to mean months or minutes depending on where it is?)
If you're saying that you have a string expressing a date and you want to turn it into a date format...then that doesn't make any sense.
If you know the format of input string, you can try below code...
public class DateFormatTest
public static void main(String  args) throws ParseException
String inputDate = "20100514101001";
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
Date myDate = df.parse(inputDate);
SimpleDateFormat dfNext = new SimpleDateFormat("dd/MM/yyyy hh mm ss");
System.out.println("Formatted Date: " + dfNext.format(myDate));
Thank you Paul for ur input.
Actually the input is a String from LDAP.
while showing it on the JSP it was not properly formatted.
I tried the following code,
formatter = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss ");
lastDate = formatter.format(lastLoginDateTime);