Java Time Format conversion

Source: Internet
Author: User

Recently started writing background Java in the project, before always engaged in front-end development, the company needs to add individuals also want to learn some Java background related knowledge, slowly accumulate practice. The following summarizes some Java in the time format conversion some of the methods, but also for beginners reference.

1SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");//to define the format of the date string to output2Date StartTime =NewDate ();3   4String starttimesting =Sdf.format (starttimen);5Calendar C = calendar.getinstance ();//get a Calendar instance object6C.settime (StartTime);//set to Current time

7C.add (calendar.date,-7);//you can set the time to 7 days before the positive number is after the current date8C.set (calendar.hour_of_day,0);//the hour is set to 0 o'clock on the same day; Get method get time, such as C.get (Canlendar.hour_of_day)9C.set (calendar.minute, 0);//set the minute to 0 minutes of the dayTenC.set (calendar.second,0);//set the seconds to the current 0 seconds OneDate endTime = C.gettime ();//Time Object Endtime format, for example: Wed June 00:00:00 CST AString endtimesting = Sdf.format (endTime);//endtimestring to the specified format string, such as: 2017-06-14 00:00:00 - -String stringtodate = "2017-06-26 08:23:21"; theDate stringtodate = Sdf.parse (stringtodate);//Parse method converts character creation to a time object, format: Mon June 08:23:21 CST

Java Time Format 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.