Java程式中使用XXXX-XX-XX XX:XX:XX格式的日期
Date date = new Date();
System.out.println(date.toLocaleString());
以上程式是使用上述格式列印出當前的日期。
以下是根據上述格式的字串構造出一個date物件供程式使用
public static Date constructDate(String time){
boolean result = Pattern.matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}", time);
if(!result)
return null;
String ymd = time.split(" ")[0];
String hms = time.split(" ")[1];
String[] ymds = ymd.split("-");
String[] hmss = hms.split(":");
return new Date(Integer.parseInt(ymds[0])-1900,Integer.parseInt(ymds[1])-1,Integer.parseInt(ymds[2]),
Integer.parseInt(hmss[0]),Integer.parseInt(hmss[1]),Integer.parseInt(hmss[2]));
}
相關文章
- Go 自定義日期時間格式解析解決方案 - 解決 `parsing time xx as xx: cannot parse xx as xx` 錯誤Go
- I/O流中的BufferedXXXStream與DataXXXStream、ObjectXXStreamObject
- Error querying database. XXXXXXXXXXXXX, No database selected。ErrorDatabase
- C++ vector<std::tuple<XXX, XXX, XXX>>C++
- Internal Error with background job scheduling XXXXXXXXXXXXX.Error
- QT中error: xxx does not name a type xxx錯誤QTError
- IDEA Error:java xxxx 程式包不存在IdeaErrorJava
- could not connect to redis Instance at xxx.xxx.xxx.xxx:6379Redis
- // @require file://C:xxxxxxxxx.jsUIJS
- Error building Player: Win32Exception: ApplicationName=‘xxxxxxxxxxxxxxxxxx//sdk\tools\zipalign.exe' ...ErrorUIWin32ExceptionAPP
- XXX使用指南
- mysql Incorrect key file for table ‘/xxxxxxxx/xxxx.MYI'; try to repair itMySqlAI
- 【問題解決】java.sql.SQLException: null, message from server: “Host ‘xxx.xx.xx.xxx‘ is blocked because ofJavaSQLExceptionNullServerBloC
- undefine macro xxxxxMac
- 使用req.session.xxx時出現 Cannot set property ‘xxxx‘ of undefinedSessionUndefined
- Oracle案例08——xx.xx.xx.xx,表空間 SYSAUX 使用率>95%%OracleUX
- Struts2中there is no action mapped for acion name (/XXXXX)APP
- [Linux] mutt /xxxx/xxxx/sent is not a mailbox.LinuxAI
- (徵文模板參考)xx技能樹/職業路線評測-xxxxxxxx
- java.sql.BatchUpdateException: Date truncation: Out of range value for column xxxxxJavaSQLBATException
- CentOS 報錯 java.net.UnknownHostException: xxxxxx: 未知的名稱或服務CentOSJavaException
- Spring:錯誤No bean named 'xxxxxxx' availableSpringBeanAI
- Permission denied:user=xxx,access=WRITE,inode=xxx
- Thread(Runnable xxx)中的問題thread
- JAVA -Xms -Xmx -XX:PermSize -XX:MaxPermSize 區別Java
- 再編寫程式碼中報錯:CS8107 C# 7.0 中不支援功能“xxxxxx”。請使用 7.1 或更高的語言版本。C#
- 報錯xxxx of undefinedUndefined
- 用意念寫程式,真的brain xxxx languageAI
- Action Script for resource 'ora.xxxx.xxxx2.inst' stdout redirection failed forAI
- #Java教程:File類:檔案、目錄的建立、刪除、判斷、getXXX、canXXX @FDDLCJava
- 解決程式中Error creating bean with name 'XXXXX‘ defined in class path resource [application的異常ErrorBeanAPP
- Maven專案報錯:No bean named 'xxxxxx' availableMavenBeanAI
- value xxx for the flexfield segment customer:does not exist in the value set xxxxFlex
- Python 原始碼理解: '+=' 和 'xx = xx + xx' 的區別Python原始碼
- Linux下編譯國標GB28181視訊推流元件EasyGBD報錯undefined reference to `xxxxxxxx@GLIBC_xxxxx‘解決Linux編譯元件Undefined
- Linux虛擬機器配置IP時提示:determining ip information for ip xxx.xxx.xxx.xxx address is alreadyLinux虛擬機ORM
- Spring 中 @EnableXXX 註解的套路Spring
- springboot報錯無法讀取配置檔案中的屬性:Could not resolve placeholder ‘xxxx‘ in value “${xxxx}Spring Boot