public long str2Date(String dateString){ public java.util.Date str2Date(String dateString,String formatString){ DateFormat format = new SimpleDateFormat(formatString); try{ java.util.Date date = format.parse(dateString); return date; }catch(ParseException e){ e.printStackTrace(); return null; } } public long str2Time(String dateString,String formatString){ java.util.Date date = str2Date(dateString, formatString); if(date==null)return 0; return date.getTime(); } @Test public void testDate(){ String date1 = "2016-02-03 00:21:33"; String format1 = "yyyy-MM-dd hh:mm:ss"; long time = str2Time(date1, format1); System.out.println(System.currentTimeMillis() - str2Time(date1, format1)); }
I'm a software engineer, interested learning the best technologies, and contribute to the industry.
Tuesday, February 2, 2016
DateFormat
SimpleDateFormat:
Labels:
Java Utils
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment