There is such a string: "20070911121547 ",
Converted to time format: 12:15:47
Java Code
-
- Public Class Bb {
-
- Public Static Void Main (string [] ARGs ){
-
- // Todo auto-generated method stub
-
- Simpledateformat df =New Simpledateformat ("Yyyymmddhhmmss");
-
- String datestring ="20071128175545";
-
- Try {
- Date = DF. parse (datestring );
-
- System. Out. println (DF. Format (date ));
-
- }Catch (Exception ex ){
-
- System. Out. println (ex. getmessage ());
-
- }
-
- }
-
- }
Public Class BB {public static void main (string [] ARGs) {// todo auto-generated method stub simpledateformat df = new simpledateformat ("yyyymmddhhmmss "); string datestring = "20071128175545"; try {date = DF. parse (datestring); system. out. println (DF. format (date);} catch (exception ex) {system. out. println (ex. getmessage ());}}}
Time is nothing more than the string type to the time type, or the time type to the string type, there is the processing of the previous time, the next time, and so on.
I made an example myself:
Java Code
-
- Package Com. Observe. monitoralarm. util;
-
- Import Java. Text. parseexception;
-
- Import Java. Text. simpledateformat;
-
- Import Java. Util. calendar;
-
- Import Java. Util. date;
-
- /**
-
- * Time help class
- * @ Version $ ID: dateutil.Java, V 1.1 04:29:52 Linan exp $
-
- * @ Author Linan
-
- */
-
- Public Class Dateutil {
-
- Private Calendar calendar = calendar. getinstance ();
-
- /**
-
- * Obtain the current time, in the format of yyyy-mm-dd.
-
- * @ Return
-
- */
-
- Public String getcurrentdate (){
- Simpledateformat SDF =New Simpledateformat ("Yyyy-mm-dd");
-
- Return SDF. Format (New Date ());
-
- }
-
- /**
-
- * Get the current time, custom time format
-
- * Y, M, D, H, M, minutes, seconds
-
- * @ Param dateformat the time format displayed by the output
-
- * @ Return
-
- */
-
- Public String getcurrentdate (string dateformat ){
- Simpledateformat SDF =New Simpledateformat (dateformat );
-
- Return SDF. Format (New Date ());
-
- }
-
- /**
-
- * Format the date. The default date format is yyyy-mm-dd.
-
- * @ Param date
-
- * @ Return
-
- */
-
- Public String getformatdate (date ){
-
- Simpledateformat SDF =New Simpledateformat ("Yyyy-mm-dd");
- Return SDF. Format (date );
-
- }
-
- /**
-
- * Date formatting: Custom output Date Format
-
- * @ Param date
-
- * @ Return
-
- */
-
- Public String getformatdate (date, string dateformat ){
-
- Simpledateformat SDF =New Simpledateformat (dateformat );
-
- Return SDF. Format (date );
-
- }
-
- /**
- * Returns the previous time and date of the current date. amount is the time after the current time as a negative value before the current time.
-
- * Default date format: yyyy-mm-dd
-
- * @ Param field calendar Field
-
- * Y, M, D, H, M, minutes, seconds
-
- * @ Param amount quantity
-
- * @ Return a date
-
- */
-
- Public String getpredate (string field,Int Amount ){
-
- Calendar. settime (New Date ());
- If(Field! =Null&&! Field. Equals ("")){
-
- If(Field. Equals ("Y")){
-
- Calendar. Add (calendar. Year, amount );
-
- }Else If(Field. Equals ("M")){
-
- Calendar. Add (calendar. Month, amount );
-
- }Else If(Field. Equals ("D")){
-
- Calendar. Add (calendar. day_of_month, amount );
- }Else If(Field. Equals ("H")){
-
- Calendar. Add (calendar. Hour, amount );
-
- }
-
- }Else{
-
- Return Null;
-
- }
-
- Return Getformatdate (calendar. gettime ());
-
- }
-
- /**
-
- * The previous date of a certain date
-
- * @ Param D, a date
-
- * @ Param field calendar Field
- * Y, M, D, H, M, minutes, seconds
-
- * @ Param amount quantity
-
- * @ Return a date
-
- */
-
- Public String getpredate (date D, string field,Int Amount ){
-
- Calendar. settime (d );
-
- If(Field! =Null&&! Field. Equals ("")){
-
- If(Field. Equals ("Y")){
-
- Calendar. Add (calendar. Year, amount );
- }Else If(Field. Equals ("M")){
-
- Calendar. Add (calendar. Month, amount );
-
- }Else If(Field. Equals ("D")){
-
- Calendar. Add (calendar. day_of_month, amount );
-
- }Else If(Field. Equals ("H")){
-
- Calendar. Add (calendar. Hour, amount );
-
- }
-
- }Else{
-
- Return Null;
- }
-
- Return Getformatdate (calendar. gettime ());
-
- }
-
- /**
-
- * The previous time of a certain time
-
- * @ Param date
-
- * @ Return
-
- * @ Throws parseexception
-
- */
-
- Public String getpredate (string date) Throws Parseexception {
-
- Date d =New Simpledateformat (). parse (date );
- String Pred = getpredate (D,"D",1);
-
- Date predate =New Simpledateformat (). parse (Pred );
-
- Simpledateformat SDF =New Simpledateformat ("Yyyy-mm-dd");
-
- Return SDF. Format (predate );
-
- }
-
- }