Android time Stamp Simple conversion

Source: Internet
Author: User
Tags timestamp to date

Timestamps are like 1377216000000 This format we often use in the MySQL database to convert time to timestamp or timestamp to date format, let me introduce the wirelessly timestamp operation conversion method.

First, the principle

The principle of time stamping is to convert the time format into decimal format, so that it is convenient to calculate the time. Good ~ go directly to the topic. (The following encapsulates a class, the need for students can refer to or direct copy can be used.) )

such as: August 23, 2013 after the conversion is 1377216000000

Second, step

1, create the DATEUTILSL class.

importjava.text.parseexception;importjava.text.simpledateformat;importjava.util.date; /** @author Msquirrel*/ Public classdateutils {privatesimpledateformat SF=NULL; /*gets the system time format as: "Yyyy/mm/dd"*/     Public StaticString getcurrentdate () {Date D=newdate (); SF= Newsimpledateformat ("yyyy mm month DD Day");    Returnsf.format (d); }                                         /*time stamp converted into character channeling*/     Public StaticString getdatetostring (LongTime ) {Date D=newdate (time); SF= Newsimpledateformat ("yyyy mm month DD Day");    Returnsf.format (d); }                                         /*Convert A string to a timestamp*/     Public Static Longgetstringtodate (String time) {SDF= Newsimpledateformat ("yyyy mm month DD Day"); Date Date=newdate (); Try{Date=Sdf.parse (time); } Catch(ParseException e) {//TODO auto-generated Catch blockE.printstacktrace ();    } returndate.gettime (); }

2, in the corresponding use of the place to call on it.

// Get system Current time  //timestamp converted to time format dateutils.getstringtodate (" time format " ); // time format converted to timestamp

Android time Stamp Simple conversion

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.