Advertisement
MarRab

Date

Oct 1st, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. // String to Date
  2.  
  3. String dtStart = "2010-10-15 09:27:37";  
  4. SimpleDateFormat  format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
  5. try {  
  6.     Date date = format.parse(dtStart);  
  7.     System.out.println(date);  
  8. } catch (ParseException e) {  
  9.     // TODO Auto-generated catch block  
  10.     e.printStackTrace();  
  11. }
  12.  
  13. // Date to String
  14.  
  15. SimpleDateFormat  dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
  16. try {  
  17.   Date date = new Date();  
  18.  String datetime = dateFormat.format(date);
  19.  System.out.println("Current Date Time : " + datetime);
  20. } catch (ParseException e) {  
  21.     // TODO Auto-generated catch block  
  22.     e.printStackTrace();  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement