Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Date_From_Str
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; import java.util.Map.Entry; import java.text.SimpleDateFormat; import java.text.DateFormat; class Rextester { public static void main(String args[]) { //String vDateStr = "23.09.2019T23:59:59"; String vDateStr = "23.09.2019"; Date vParsedDate = null; Map<String, String> mapDateMasks = new HashMap<>(); mapDateMasks.put("\\d{4}\\.\\d{2}\\.\\d{2}$","yyyy.mm.dd"); mapDateMasks.put("\\d{4}\\-\\d{2}\\-\\d{2}T\\d{2}:\\d{2}:\\d{2}","yyyy-mm-dd'T'HH:mm:ss"); mapDateMasks.put("\\d{4}\\-\\d{2}\\-\\d{2}$","yyyy-mm-dd"); mapDateMasks.put("\\d{4}\\.\\d{2}\\.\\d{2}T\\d{2}:\\d{2}:\\d{2}","yyyy.mm.dd'T'HH:mm:ss"); mapDateMasks.put("\\d{2}\\.\\d{2}\\.\\d{4}","dd.mm.yyyy"); mapDateMasks.put("\\d{2}\\.\\d{2}\\.\\d{4}T\\d{2}:\\d{2}:\\d{2}","dd.mm.yyyy'T'HH:mm:ss"); System.out.println("Str_Date = " + vDateStr); for (Entry<String,String> tmpDatemask : mapDateMasks.entrySet()) { System.out.println(tmpDatemask.getKey()); if (vDateStr.matches(tmpDatemask.getKey())) { System.out.println("mask ok. using template = \"" + tmpDatemask.getValue() + "\""); DateFormat df = new SimpleDateFormat(tmpDatemask.getValue()); try { vParsedDate = df.parse(vDateStr); if (vParsedDate != null) { break; } } catch (Exception e) { }; } } System.out.println("vParsedDate = " + vParsedDate); } }
run
|
edit
|
history
|
help
0
hello!
PE #5
RevArray
1
sfr
Union of Arrays
hextoepeen
練習問題
Max in 2D array
Problem: on_off