Package Com.banksteel.openerp.commons.utils;import Java.text.parseexception;import Java.text.SimpleDateFormat; Import java.util.date;/** * @description: Time conversion * @projectName: Openerp-commons * @className: Timetransf.java * @author: * @c reatetime:2016 July 28 pm 6:06:53 * @version 1.0 */public Class timetransf{/** * @description: string time conversion growth Integer Time * @param-hour character String time * @param format time representation * @return long time * @throws parseexception * @author: * @createTime: July 28, 2016 PM 6:07:33 */publi C Static Long Stringtolong (string time, string format) throws Parseexception{if (Time!=null) {return new SimpleDateFormat ( Format). Parse (time). GetTime ();} return null;} /** * @description: Long integer time converted to string time * @param time long * @param format time representation * @return String type Time * @author: * @createTime: 201 6 July 28 pm 6:10:50 */public static string longtostring (Long time, String format) {if (time!=null) {return new SimpleDateFormat (format). Format (new Date);} return null;} public static void Main (string[] args) throws Parseexception{long CurreNttimemillis = System.currenttimemillis (); String str = timetransf.longtostring (Currenttimemillis, "Yyyy-mm-dd HH:mm:ss. SSS "); System.out.println (str); Long t = timetransf.stringtolong (str, "Yyyy-mm-dd HH:mm:ss. SSS "); System.out.println (t); String str1 = timetransf.longtostring (Currenttimemillis, "Yyyy-mm-dd HH:mm:ss"); System.out.println (STR1); Long T1 = Timetransf.stringtolong (str1, "Yyyy-mm-dd HH:mm:ss"); SYSTEM.OUT.PRINTLN (t1); String str2 = timetransf.longtostring (Currenttimemillis, "yyyy-mm-dd"); System.out.println (STR2); Long t2 = Timetransf.stringtolong (str2, "yyyy-mm-dd"); System.out.println (t2);}}
2
Java time Long and string convert each other