java time processing tools

+++++++++

++++++++++

Package DataUtils; 

Import java.text.ParseException;
 Import the java.text.SimpleDateFormat;
 Import the java.util.Calendar;
 Import java.util.Date; 

public  class DataUtil {
     / ** 
     * different preset time format 
     * / 
    // precise to date (English) EG: 2019-12-31 
    public  static String FORMAT_LONOGRAM = "yyyy-MM-dd" ;
     // full time in minutes and seconds when accurate to (English) eg: 2010-11-11 12:12: 12 is 
    public  static String FORMAT_FULL = "the mM-dd-YYYY HH: mm: SS" ;
     // millisecond accuracy full time (English) EG: 2019-11-11 12 is: 12 is: 12.55 
    public  staticFORMAT_LONOGRAM_MILL = String "yyyy-MM-dd HH: mm: ss.SSS" ;
     // accurate to date (Chinese) eg: 2019 On May 11 May 11 
    public  static String FORMAT_LONOGRAM_CN = "yyyy Year MM Month dd Day" ;
     // when the exact minutes and seconds of time to complete (Chinese) eg: 2019 on 11 May 11 May 12 when 12 minutes 12 seconds 
    public  static String FORMAT_FULL_CN = "when dd day HH yyyy Year MM minutes SS seconds MM month" ;
     // accurate to full time in milliseconds (Chinese) 
    public  static String FORMAT_LONOGRAM_MILL_CN = "yyyy Year MM month dd day HH MM minutes SS seconds when SSS millisecond" ;
     / ** 
     * the default preset time format 
     * / 
    public  static String getDefaultFormat () {
         return FORMAT_FULL; 
    } 
    / **
     * Pre-formatted date format 
     * / 
    public  static String the format (a Date DATE) {
         return the format (DATE, getDefaultFormat ()); 
    } 
    / ** 
     * custom format Date format 
     * / 
    Private  static String the format (a Date DATE, String the format) { 
        String value = "" ;
         IF (DATE =! null ) { 
            the SimpleDateFormat SDF = new new the SimpleDateFormat (the format); 
            value = sdf.format (DATE); 
        } 
        return value; 
    } 
    / ** 
     * according to a preset default format, returns the current date 
     * /
    public  static String getNow () {
         return the format ( new new a Date ()); 
    } 
    / ** 
     * Custom time format, returns the current date 
     * / 
    public  static String getNow (the format String) {
         return the format ( new new a Date (), the format) ; 
    } 
    / ** 
     * The default preset time String-> a Date 
     * / 
    public  static a Date the parse (String strDate) {
         return the parse (strDate, getDefaultFormat ()); 
    } 
    / ** 
     * custom time format: Stirng-> Date 
     * / 
    public  static = a Date the parse (strDate String, String the format) {
        SDF the SimpleDateFormatnew new the SimpleDateFormat (the format);
         the try {
             return sdf.parse (strDate); 
        } the catch (a ParseException E) { 
            e.printStackTrace (); 
            return  null ; 
        } 
    } 
    / ** 
     * Based on the specified date increase 
     * @param NUM positive to push, move forward negative
      * / 
    public  static a Date addMobth (a Date DATE, int NUM) { 
        Calendar CAL = Calendar.getInstance (); 
        cal.setTime (DATE); 
        cal.add (the Calendar.MONTH, NUM); 
        return CAL .getTime ();
    }
    

    public static void main(String[] args) {
        //String time = format(new Date());
        System.out.println(getNow(FORMAT_FULL_CN));
    }
    
    
}

 

++++++

Unfinished .........

 

Reference Bowen: https: //blog.csdn.net/qq_41144667/article/details/103745529

Guess you like

Origin www.cnblogs.com/zhaoKeju-bokeyuan/p/12125711.html