Time Format Daquan date

Source: Internet
Author: User
Public class vedate {/*** get current time ** @ return returns the time type yyyy-mm-dd hh: mm: SS */public static date getnowdate () {date currenttime = new date (); simpledateformat formatter = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); string datestring = formatter. format (currenttime); parseposition Pos = new parseposition (8); Date currenttime_2 = formatter. parse (datestring, POS); Return currenttime_2;}/*** get the current time ** @ Return returns the short-time format yyyy-mm-dd */public static date getnowdateshort () {date currenttime = new date (); simpledateformat formatter = new simpledateformat ("yyyy-mm-dd"); string datestring = formatter. format (currenttime); parseposition Pos = new parseposition (8); Date currenttime_2 = formatter. parse (datestring, POS); Return currenttime_2;}/*** get the current time ** @ return returns the string format yyyy-mm-dd hh: mm: SS */publi C static string getstringdate () {date currenttime = new date (); simpledateformat formatter = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); string datestring = formatter. format (currenttime); Return datestring;}/*** get current time ** @ return returns the short-time string format yyyy-mm-dd */public static string getstringdateshort () {date currenttime = new date (); simpledateformat formatter = new simpledateformat ("yyyy-mm-dd "); String datestring = formatter. format (currenttime); Return datestring;}/*** Acquisition Time Hour: minute; second hh: mm: SS ** @ return */public static string gettimeshort () {simpledateformat formatter = new simpledateformat ("HH: mm: SS"); Date currenttime = new date (); string datestring = formatter. format (currenttime); Return datestring;}/*** converts a long-time string to a time string in yyyy-mm-dd hh: mm: SS ** @ Param strdate * @ return */Public St Atic date strtodatelong (string strdate) {simpledateformat formatter = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); parseposition Pos = new parseposition (0 ); date strtodate = formatter. parse (strdate, POS); Return strtodate;}/*** converts long-time format to string yyyy-mm-dd hh: mm: SS ** @ Param datedate * @ return */public static string datetostrlong (Java. util. date datedate) {simpledateformat formatter = new simpl Edateformat ("yyyy-mm-dd hh: mm: SS"); string datestring = formatter. format (datedate); Return datestring ;} /*** convert the short-time format to the string yyyy-mm-dd ** @ Param datedate * @ Param K * @ return */public static string datetostr (Java. util. date datedate) {simpledateformat formatter = new simpledateformat ("yyyy-mm-dd"); string datestring = formatter. format (datedate); Return datestring;}/*** converts a string in the short-time format to the time yyyy-m M-dd ** @ Param strdate * @ return */public static date strtodate (string strdate) {simpledateformat formatter = new simpledateformat ("yyyy-mm-dd "); parseposition Pos = new parseposition (0); Date strtodate = formatter. parse (strdate, POS); Return strtodate;}/*** get the current time ** @ return */public static date getnow () {date currenttime = new date (); return currenttime;}/*** extract the last day of a month ** @ Param d Ay * @ return */public static date getlastdate (long day) {date = new date (); long date_3_hm = date. gettime ()-3600000*34 * day; Date date_3_hm_date = new date (date_3_hm); Return date_3_hm_date ;} /*** get the current time ** @ return string yyyymmdd hhmmss */public static string getstringtoday () {date currenttime = new date (); simpledateformat formatter = new simpledateformat ("yyyymmdd hhmmss"); string Datestring = formatter. format (currenttime); Return datestring;}/*** get current hour */public static string gethour () {date currenttime = new date (); simpledateformat formatter = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); string datestring = formatter. format (currenttime); string hour; hour = datestring. substring (11, 13); Return hour;}/*** get the current minute ** @ return */public static string gettime () {dat E currenttime = new date (); simpledateformat formatter = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); string datestring = formatter. format (currenttime); string min; min = datestring. substring (14, 16); Return min;}/*** returns the format of the current time based on the time input by the user. If the format is yyyymmdd, note that the letter y cannot be capitalized. ** @ Param sformat * yyyymmddhhmmss * @ return */public static string getuserdate (string sformat) {date currenttime = new date (); simpledateformat formatter = new simpledateformat (sformat ); string datestring = formatter. format (currenttime); Return datestring;}/*** difference between two hours, must ensure that the two times are in the format of "HH: mm, returns the minute */public static string gettwohour (string ST1, string st2) of the week type {string [] KK = NULL; string [] JJ = NULL; KK = st1.split (":"); JJ = st2.split (":"); If (integer. parseint (kk [0]) <integer. parseint (JJ [0]) Return "0"; else {Double Y = double. parsedouble (kk [0]) + double. parsedouble (kk [1])/60; double U = double. parsedouble (JJ [0]) + double. parsedouble (JJ [1])/60; If (Y-u)> 0) return y-U + ""; else return "0 ";}} /*** get the number of days between two days */public static string gettwoday (string sj1, string SJ 2) {simpledateformat myformatter = new simpledateformat ("yyyy-mm-dd"); long day = 0; try {Java. util. date = myformatter. parse (sj1); Java. util. date mydate = myformatter. parse (sj2); Day = (date. gettime ()-mydate. gettime ()/(24*60*60*1000);} catch (exception e) {return "";} return day + "";} /*** push before or after the time. JJ indicates the minute. */public static string getpretime (string sj1, string JJ) {simpl Edateformat format = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); string mydate1 = ""; try {date date1 = format. parse (sj1); long time = (date1.gettime ()/1000) + integer. parseint (jj) * 60; date1.settime (time * 1000); mydate1 = format. format (date1);} catch (exception e) {} return mydate1;}/*** get a time delay or several days forward, nowdate is the time, delay is the number of days after the forward or backward delay */public static string getnextday (string nowdate, strin G delay) {try {simpledateformat format = new simpledateformat ("yyyy-mm-dd"); string mdate = ""; Date d = strtodate (nowdate ); long mytime = (D. gettime ()/1000) + integer. parseint (Delay) * 24*60*60; D. settime (mytime * 1000); mdate = format. format (d); Return mdate;} catch (exception e) {return "";}} /*** determine whether to renew the subscription ** @ Param ddate * @ return */public static Boolean isleapyear (string ddate ){/** * Detailed Design: 1. it is a leap year to be divisible by 400; otherwise: 2. it cannot be divisible by four, but it is not a leap year 3. it is a leap year * 3 if it can be divisible by 4 and cannot be divisible by 100. it is not a leap year */date d = strtodate (ddate); gregoriancalendar GC = (gregoriancalendar) calendar. getinstance (); GC. settime (d); int year = GC. get (calendar. year); If (Year % 400) = 0) return true; else if (Year % 4) = 0) {If (Year % 100) = 0) return false; else return true;} else return false;}/*** returns the US time format 26 Apr 2006 ** @ Param Str * @ return */public static string getedate (string Str) {simpledateformat formatter = new simpledateformat ("yyyy-mm-dd "); parseposition Pos = new parseposition (0); Date strtodate = formatter. parse (STR, POS); string J = strtodate. tostring (); string [] K = J. split (""); Return K [2] + k [1]. touppercase () + K [5]. substring (2, 4);}/*** get the last day of a month ** @ Param dat * @ return */public static String getenddateofmonth (string dat) {// yyyy-mm-dd string STR = dat. substring (0, 8); string month = dat. substring (5, 7); int MON = integer. parseint (month ); if (MON = 1 | MON = 3 | MON = 5 | MON = 7 | MON = 8 | MON = 10 | MON = = 12) {STR + = "31";} else if (MON = 4 | MON = 6 | MON = 9 | MON = 11) {STR + = "30" ;}else {If (isleapyear (DAT) {STR + = "29" ;}else {STR + = "28 ";} Return STR ;} /*** determine whether two times are in the same week ** @ Param date1 * @ Param date2 * @ return */public static Boolean issameweekdates (date date1, date date2) {calendar cal1 = calendar. getinstance (); Calendar cal2 = calendar. getinstance (); cal1.settime (date1); cal2.settime (date2); int subyear = cal1.get (calendar. year)-cal2.get (calendar. year); If (0 = subyear) {If (cal1.get (calendar. week_of_year) = cal2.g Et (calendar. week_of_year) return true;} else if (1 = subyear & 11 = cal2.get (calendar. month) {// if the last week of January 1, December spans the first week of the next year, the last week is counted as the first week of the next year if (cal1.get (calendar ar. week_of_year) = cal2.get (calendar. week_of_year) return true;} else if (-1 = subyear & 11 = cal1.get (calendar. month) {If (cal1.get (calendar. week_of_year) = cal2.get (calendar. week_of_year) return true;} return false;}/*** generates a weekly sequence, The week ** @ return */public static string getseqweek () {calendar Ar c = calendar ar. getinstance (locale. china); string week = integer. tostring (C. get (calendar. week_of_year); If (Week. length () = 1) Week = "0" + week; string year = integer. tostring (C. get (calendar. year); return year + week;}/*** get the date of the day of the week where a date is located, to find the number of Monday in the week of March February 3, 2002, ** @ Param sdate * @ Param num * @ return */Public stat IC string getweek (string sdate, string num) {// convert it to date dd = vedate. strtodate (sdate); Calendar c = calendar. getinstance (); C. settime (dd); If (Num. equals ("1") // returns the date C. set (calendar. day_of_week, calendar. monday); else if (Num. equals ("2") // returns the date C. set (calendar. day_of_week, calendar. tuesday); else if (Num. equals ("3") // returns the date C. set (calendar. day_of_week, calendar. wednesday ); Else if (Num. equals ("4") // returns the date C. set (calendar. day_of_week, calendar. thursday); else if (Num. equals ("5") // returns the date of Friday C. set (calendar. day_of_week, calendar. friday); else if (Num. equals ("6") // returns the date C. set (calendar. day_of_week, calendar. saturday); else if (Num. equals ("0") // returns the date of Sunday C. set (calendar. day_of_week, calendar. sunday); return New simpledateformat ("yyyy-mm-dd "). format (C. g Ettime ();}/*** returns the day of the week string ** @ Param sdate * @ return */public static string getweek (string sdate) based on a date) {// convert to date = vedate. strtodate (sdate); Calendar c = calendar. getinstance (); C. settime (date); // int hour = C. get (calendar. day_of_week); // the day of the week in hour. The value range is 1 ~ 7 // 1 = Sunday 7 = Saturday, and other statements return New simpledateformat ("eeee "). format (C. gettime ();} public static string getweekstr (string sdate) {string STR = ""; STR = vedate. getweek (sdate); If ("1 ". equals (STR) {STR = "Sunday";} else if ("2 ". equals (STR) {STR = "Monday";} else if ("3 ". equals (STR) {STR = "Tuesday";} else if ("4 ". equals (STR) {STR = "Wednesday";} else if ("5 ". equals (STR) {STR = "Thursday";} else if ("6 ". equals (STR) {STR = "Friday";} else if ("7 ". equals (STR) {STR = "Saturday";} return STR ;} /*** number of days between two times ** @ Param date1 * @ Param date2 * @ return */public static long getdays (string date1, string date2) {If (date1 = NULL | date1.equals ("") return 0; If (date2 = NULL | date2.equals ("") return 0; // convert to Standard Time simpledateformat myformatter = new simpledateformat ("yyyy-mm-dd"); Java. util. date = NULL; Java. util. date Mydate = NULL; try {date = myformatter. parse (date1); mydate = myformatter. parse (date2);} catch (exception e) {} Long Day = (date. gettime ()-mydate. gettime ()/(24*60*60*1000); return day;}/*** form the following calendar, returns a structure based on the input time. It is Sunday, Tuesday, Thursday, and Saturday of the current month. * This function returns the date of the first Sunday of the calendar. ** @ Param sdate * @ return */public static string getnowmonth (string sdate) {// obtain the number one sdate = sdate of the month. Substring (0, 8) + "01"; // obtain the date of the day of the week on the first day of the month = vedate. strtodate (sdate); Calendar c = calendar. getinstance (); C. settime (date); int u = C. get (calendar. day_of_week); string newday = vedate. getnextday (sdate, (1-u) + ""); Return newday ;} /*** obtain the primary key of the database. The generated format is yyyymmddhhmmss + k-bit random number. ** @ Param K * indicates the number of random numbers, you can set */public static string getno (int K) {return getuserdate ("yyyymmddhhmmss") + getrandom (K);}/*** returns a random number ** @ Param I * @ return */public static string getrandom (int I) {random jjj = new random (); // int suijishu = jjj. nextint (9); if (I = 0) Return ""; string JJ = ""; for (int K = 0; k <I; k ++) {JJ = JJ + jjj. nextint (9);} return JJ;}/***** @ Param ARGs */public static Boolean rightdate (string date) {simpledateformat SDF = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); if (Date = NULL) return false; If (date. length ()> 10) {SDF = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");} else {SDF = new simpledateformat ("yyyy-mm-dd");} Try {SDF. parse (date);} catch (parseexception PE) {return false;} return true ;} /*************************************** * **********************************/nd = 1 indicates that the returned value contains the year. // YF = 1 indicates that the returned value contains the month. // RQ = 1 indicates that the returned value contains the date. // format indicates that the returned format is 1 * year. Returns 2 with a hyphen-return // 3 with a slash/return 4 with an abbreviation without other symbols return // 5 with a dot. return *************************************** * ********************************/public static string getstringdatemonth (string sdate, string nd, string YF, string RQ, string format) {date currenttime = new date (); simpledateformat formatter = new simpledateformat ("yyyy-mm-dd "); string datestring = formatter. format (currenttime); string s_nd = Date String. substring (0, 4); // year string s_yf = datestring. substring (5, 7); // month string s_rq = datestring. substring (8, 10); // Date string sreturn = ""; ROC. util. mychar MC = new Roc. util. mychar (); If (sdate = NULL | sdate. equals ("") |! MC. isdate (sdate) {// process null values if (Nd. equals ("1") {sreturn = s_nd; // processing interval if (format. equals ("1") sreturn = sreturn + "year"; else if (format. equals ("2") sreturn = sreturn + "-"; else if (format. equals ("3") sreturn = sreturn + "/"; else if (format. equals ("5") sreturn = sreturn + ". ";} // process the month if (YF. equals ("1") {sreturn = sreturn + s_yf; If (format. equals ("1") sreturn = sreturn + "month"; else I F (format. equals ("2") sreturn = sreturn + "-"; else if (format. equals ("3") sreturn = sreturn + "/"; else if (format. equals ("5") sreturn = sreturn + ". ";}// processing date if (RQ. equals ("1") {sreturn = sreturn + s_rq; If (format. equals ("1") sreturn = sreturn + "" ;}} else {// is not a null value and is also a valid date value, first, convert it to the standard time format sdate = Roc. util. rocdate. getokdate (sdate); s_nd = sdate. substring (0, 4); // year s_yf = sdate. Substring (5, 7); // month s_rq = sdate. substring (8, 10); // Date If (Nd. equals ("1") {sreturn = s_nd; // processing interval if (format. equals ("1") sreturn = sreturn + "year"; else if (format. equals ("2") sreturn = sreturn + "-"; else if (format. equals ("3") sreturn = sreturn + "/"; else if (format. equals ("5") sreturn = sreturn + ". ";} // process the month if (YF. equals ("1") {sreturn = sreturn + s_yf; If (format. equals ("1 ")) Sreturn = sreturn + "month"; else if (format. equals ("2") sreturn = sreturn + "-"; else if (format. equals ("3") sreturn = sreturn + "/"; else if (format. equals ("5") sreturn = sreturn + ". ";}// processing date if (RQ. equals ("1") {sreturn = sreturn + s_rq; If (format. equals ("1") sreturn = sreturn + "" ;}} return sreturn;} public static string getnextmonthday (string sdate, int m) {sdate = getokdate (sdate); Int year = integer. parseint (sdate. substring (0, 4); int month = integer. parseint (sdate. substring (5, 7); month = month + m; If (month <0) {month = month + 12; year = year-1 ;} else if (month> 12) {month = month-12; year = year + 1;} string smonth = ""; if (month <10) smonth = "0" + month; else smonth = "" + month; return year + "-" + smonth + "-10";} public static string getokdate (Str Ing sdate) {If (sdate = NULL | sdate. Equals ("") return getstringdateshort (); If (! Vestr. isdate (sdate) {sdate = getstringdateshort () ;}// convert "/" to "-" sdate = vestr. replace (sdate, "/", "-"); // If the length is only 8 bits, convert if (sdate. length () = 8) sdate = sdate. substring (0, 4) + "-" + sdate. substring (4, 6) + "-" + sdate. substring (6, 8); simpledateformat formatter = new simpledateformat ("yyyy-mm-dd"); parseposition Pos = new parseposition (0); Date strtodate = formatter. parse (sdate, POS); string datestring = formatter. format (strtodate); Return datestring ;}

Time Format Daquan date

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.