How Java gets the start and end times of the day

Source: Internet
Author: User

public static void Main (string[] args) {Calendar C1 = new GregorianCalendar (); C1.set (calendar.hour_of_day, 0); C1.set ( Calendar.minute, 0); C1.set (Calendar.second, 0); System.out.println (C1.gettime (). toLocaleString ()); Calendar C2 = new GregorianCalendar (), C2.set (Calendar.hour_of_day, 23°c); C2.set (Calendar.minute); C2.set ( Calendar.second, 59); System.out.println (C2.gettime (). toLocaleString ());}

Slightly modified under

/** * @param args */public static void main (string[] args) {Calendar calendar = calendar.getinstance (); Calendar.settime (NE W Date ()); Calendar.set (calendar.hour_of_day, 0); Calendar.set (Calendar.minute, 0); Calendar.set (Calendar.second, 0) ;D ate start = Calendar.gettime (); Calendar.add (Calendar.day_of_month, 1); Calendar.add (Calendar.second,-1);D ate end = Calendar.gettime ();    System.out.println (start);    SYSTEM.OUT.PRINTLN (end);}

or more simple.

/** * @param args * @throws parseexception  */public static void Main (string[] args) throws ParseException {Calendar CA Lendar = Calendar.getinstance (); Calendar.settime (new Date ()); Calendar.set (calendar.hour_of_day, 0); Calendar.set ( Calendar.minute, 0); Calendar.set (Calendar.second, 0);D ate start = Calendar.gettime (); Calendar.add (calendar.day_of_ MONTH, 1); Calendar.add (Calendar.second,-1);D ate end = Calendar.gettime ();    System.out.println (start);    SYSTEM.OUT.PRINTLN (end);        /* Other    simpledateformat/* = Formater = new SimpleDateFormat ("Yyyy/mm/dd");    SimpleDateFormat formater2 = new SimpleDateFormat ("Yyyy/mm/dd HH:mm:ss");        Start = Formater2.parse (Formater.format (New Date ()) + "00:00:00");    End = Formater2.parse (Formater.format (New Date ()) + "23:59:59");        System.out.println (start);    SYSTEM.OUT.PRINTLN (end);}

Source:http://bbs.csdn.net/topics/390562030?page=1

How Java Gets the start and end times of the day

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.