Java time Formatting (2016.04.12 12:32:55)

Source: Internet
Author: User
Tags date1

The time format entered is as follows: 2016.04.12 12:32:55:

To get a date in a certain format, the method of time

1String startstring = "2016.04.25 12:25:44"2SimpleDateFormat SF1 =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");3SimpleDateFormat SF2 =NewSimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");4Date date1 =Sf1.parse (startstring);5Date Date2 =Sf2.parse (startstring);6String timeString1 =Sf1.format (date1);7String timeString2 =Sf2.format (date2);8 System.out.printIn (timeString1);9System.out.printIn (TIMESTRING2);

The output results are: 2016-04-25 12:25:44

2016-04-25 00:25:44

The output shows that the format is 12 hours if it is hh, and HH is a 24-hour system.

If you just want to get a specific time-hour minute, the method is:

String startstring = "2016.04.25 12:25:44"new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"=  = Dateformat.format ("hh:mm", Date1)                    . toString (); System.out.printIn (STARTT);

The output is: 12:25

  

Java time Formatting (2016.04.12 12:32:55)

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.