Java Background Time Calculation

Source: Internet
Author: User

Converts milliseconds to days and seconds

public static void Main (string[] args) {
Date date = new Date ();
System.out.println (Date.gettime ());
Long a = Date.gettime ();

Date date1 = new Date (a);
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");
String strdate = Sdf.format (date1);

System.out.println (strdate);

}

Compare two times the size of a string into a time date type

public static void Main (string[] args) throws ParseException {
Date date = new Date ();
String strdate = "2016-03-02 22:12:11";
SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Date date1 = Format.parse (strdate);
if (Date.gettime () > Date1.gettime ())
System.out.println ("Now Time is big");
Else
System.out.println ("String time is large");
}

The current time plus one day, calculate the time to add subtraction

public static void Main (string[] args) throws ParseException {


SimpleDateFormat SF = new SimpleDateFormat ("Yyyy-mm-dd");
Calendar C = calendar.getinstance ();
System.out.println ("Current Time:" +sf.format (C.gettime ()));

C.add (Calendar.day_of_month, 1);
System.out.println ("Add Day after Date:" +sf.format (C.gettime ()));
}

SQL for determining the time-date size in MyBatis

<! [Cdata[and Date_format (sud.endtime, '%y-%m-%d ') >= Date_format (now (), '%y-%m-%d ')]]>

Java Background Time Calculation

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.