Java time Long and string convert each other

Source: Internet
Author: User
Tags string format

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.