Feel Java's time date processing capabilities!

zhaozj2021-02-16  56

I have been doing a program recently, I am going to read the data in Oracle to SQL Server. I have n'thing. I think I can do it for a while, but take a closer look at Oracle's data, I found it is string. Save, and more than 24 hours, one question, the reason is that the time record is 48 hours by shift. However, the time required to send to SQLServer is a datetime type. I can't think of a good way for a time. Only analyze the string, get the year, month, day, time, minute, second, then the unreasonable time is handled, What can I still have? ? What really wants to do, the more simple procedures, if this is a unnecessary detail, it is true! No, Java's library is so rich, there must be a good way! So, I found it in Help, Date, Calendar, Dateformat turned over, found a mutual relationship, and finally let me understand, find a relatively convenient way to solve, I will take it out with you!

SimpleDateFormat DF = New SimpleDateFormat ("YYYYMMDDHMMS"); Date Date; Try {Date = DF.PARSE ("2003124291921"); DF.ApplyPattern ("YYY-MM-DD HH: MM: SS"); System.out.Println (df.format (date));} catch (parseException e) {system.out.println (e.tostring ());}

The above code is the process of my entire analysis date time, simple? Haha! This is attributed to the java rich class library, and I also wrote a formatted time that got it with the same day:

Public String getPriorday (int offset, string splitdate, string splittime) {Calendar another = calendar.getInstance (); THEDAY.ADD (Calendar.date, Offset);

DF.ApplyPattern ("YYYY" SPLITDATE "MM" " " HH " SplitTime " mm " SplitTime " SS "); returnif.format ());}

The OFFSET represents the number of days that differ from the day, splitdate represents the separator during the day, and the splittime represents the separator between the time.

转载请注明原文地址:https://www.9cbs.com/read-24056.html

New Post(0)