Java: Today, tomorrow, the state of the day acquired, cross-year

Source: Internet
Author: User

Exactly on December 31 (today), showing January 1 (tomorrow), January 2 (the day After Tomorrow), 2014 years later, welcomed the 2015.I wish you a happy New Year!





Import Java.io.file;import Java.util.calendar;import Java.util.timezone;public class Test {public static void main ( String[] (args) {test test =new Test (); Test.printday ( -1); test.printday (0); Test.printday (1); Test.printday (2); Test.printday (3);} private void Printday (int tempsingle) {Calendar calendar =calendar.getinstance (); Calendar.add (Calendar.day_of_year, Tempsingle); SetTime (Calendar.gettimeinmillis ()); System.out.println (Getformattimenear3day ());} Private long timemills;public void settime (Long timemills) {this.timemills = Timemills;} Public long GetTime () {return timemills;} Public String Getformattime () {return new DateTime (GetTime ()). Getstringdateweek (Datetime.format_md_hour_minute_week );} Public String Getformattimeonlyweek () {return new DateTime (GetTime ()). Getstringdateweek (Datetime.format_md_hour_ Only_week);} Public String Getformattimenear3day () {String timetext = ""; Calendar calendar= calendar.getinstance (Timezone.gettimezone ("gmt+08:00")); int cyear = Calendar.get (Calendar.YEAR); int Ctoday = Calendar.get (calendar.day_of_year); int ctotalday = Calendar.getmaximum (calendar.day_of_year); Calendar.settimeinmillis (GetTime ()); int year = Calendar.get (calendar.year), int day = Calendar.get (calendar.day_of_ Switch (year-cyear) {case-1:default:timetext = Getnear3day (2,8); Break;case 0:timetext = Getnear3day (day,ctoday) ; break;case 1:int vday = day+ (ctotalday-ctoday) -1;timetext = Getnear3day (day+vday,day); break;} return timetext;}  Public String getnear3day (int day,int ctoday) {String timetext= "", switch (day-ctoday) {case 0:timetext= "today"; timetext + = Getformattimeonlyweek (); Break;case 1:timetext = "Tomorrow"; timetext + = Getformattimeonlyweek (); Break;case 2:timeText = "Day After Tomorrow"; Timetext + = Getformattimeonlyweek (); break;default:timetext = Getformattime (); break;} return timetext;}}


Java: Today, tomorrow, the state of the day acquired, cross-year

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.