Time string compared to current time

Source: Internet
Author: User

/* Get current time */
public static String GetCurrentTime () {
Date currenttime = new Date ();
SimpleDateFormat formatter = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String datestring = Formatter.format (currenttime);
return datestring;
}

/* Time than size */
public static int Timecompare (String t1,string T2) {
SimpleDateFormat formatter = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Calendar c1=calendar.getinstance ();
Calendar c2=calendar.getinstance ();
try {
C1.settime (Formatter.parse (t1));
C2.settime (Formatter.parse (T2));
} catch (ParseException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
int Result=c1.compareto (C2);
return result;
}

public static void Main (string[] args) {
// String coupon_valid_end = "3004-03-26 13:31:40";
// String currenttime = GetCurrentTime ();
// int flagnum = Timecompare (Coupon_valid_end, currenttime);
// System.out.println (Flagnum);
// }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Time string compared to current time

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.