Last active
October 28, 2015 12:27
-
-
Save jpt1122/e8ebc59d0cd753a03746 to your computer and use it in GitHub Desktop.
Convert java string date : One format to another format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.DateFormat; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
public class TestStringDate { | |
public static void main(String[] args) throws ParseException { | |
String strValue = "2015-07-05 19:52:00"; | |
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
DateFormat format1 = new SimpleDateFormat("MM/dd/yyyy hh:mm a"); | |
Date d1 = format.parse(strValue); | |
System.out.println(d1); | |
System.out.println(format1.format(d1)); | |
} | |
} | |
/* | |
OutPut: | |
Sun Jul 05 19:52:00 IST 2015 | |
07/05/2015 07:52 PM | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment