Java date and string, based on the day of the day to get the date and time of the last second of the day

Source: Internet
Author: User

The Java date and string are transferred to each other. Get the date and time of the last second of the day based on the day of the day


Package Com.hi;import Java.text.dateformat;import Java.text.parseexception;import Java.text.SimpleDateFormat; Import java.util.date;/** * Based on the day of the day * to get the last second of the day * database query very meaningful from the start day to the knot rate day by day query 2014-06-17 00:00:00 to 2014-06-20:23 : 59:59 * * @author Administrator * */public class Main3 {public static void main (string[] args) throws ParseException {Da Teformat format=new SimpleDateFormat ("YYYY-MM-DD");D ate d=new Date (); String Str=format.format (d); System.out.println (str);D ate d2=format.parse (str); System.out.println (D2);/////////////////gets the time to test all day int daymis=1000*60*60*24;//The millisecond of the day -1system.out.println (" The millisecond of the day-1: "+daymis");//Returns the number of milliseconds represented by this Date object since January 1, 1970 00:00:00 GMT. Long Curmillisecond=d2.gettime ();//millisecond System.out.println of the Day ("Curmillisecond:" +new Date (Curmillisecond)); long Resultmis=curmillisecond+ (DAYMIS-1); The last second of the day System.out.println ("Resultmis:" +resultmis);D Ateformat format2=new simpledateformat ("Yyyy-mm-dd HH:mm:ss") ;//Get the time I need the last second of the day date resultdate=new date (Resultmis); System.ouT.println ("Resultdate:" +resultdate); System.out.println ("FormatResult:" +format2.format (Resultdate));}} /** * Output:2014-06-17tue June 00:00:00 CST 20,141-day millisecond -1:86400000curmillisecond:tue June 00:00:00 CST 2014resultmis:14 03020799999resultdate:tue June 23:59:59 CST 2014formatresult:2014-06-17 23:59:59*/


Java date and string, based on the day of the day to get the date and time of the last second 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.