I have a string, is there a simple way to validate whether the string represents ISO 8601 week number in java?
String s="2012-W43-5"
This one represents 5 th day in 43 rd week in 2012.
Just check if SimpleDateFormat#parse()
doesn't throw a ParseException
.
String string = "2012-W43-5";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-'W'w-u");
sdf.setLenient(false);
Date date = sdf.parse(string);
Note that the setLenient(false)
makes it non-lenient which thus means that overflowed values won't roll over.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.