Java String type Time comparison size

Source: Internet
Author: User
Tags dateformat

I wrote a function of time in the evening, and here we summarize

Package Com.zz.bridge.impl;import Java.text.dateformat;import Java.text.parseexception;import Java.text.simpledateformat;import java.util.calendar;/** * Test class * Copyright June 9, 2015 * created by TXXS * All right Reserve D */public class Bridgetest {public static void main (String args[]) {DateFormat df = new SimpleDateFormat ("Yyyymm");//Get CAL Endar instance Calendar currenttime = Calendar.getinstance (); Calendar comparetime = Calendar.getinstance ();    try {    //convert string to date type Currenttime.settime (Df.parse ("201406")), Comparetime.settime (Df.parse ("201506"));} catch ( ParseException e) {//TODO auto-generated catch Blocke.printstacktrace ();}    Use the Calendar method to compare the size    if (Currenttime.compareto (Comparetime) > 0) {    System.out.println ("The former time is small");} Else{system.out.println ("Behind Time");}    Converted to a number after the comparison size int startTime = Integer.parseint ("201406"); int endTime = Integer.parseint ("201506"); System.out.println (Endtime-starttime);}}


Java String Type time comparison size

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.