How to parse time in Java?
•
Java
I want to know whether Java has a built-in method for parsing time / date, as shown below:
5m1w5d3h10m15s
This is 5 months, 1 week, 5 days, 3 hours, 10 minutes, 15 seconds
Solution
Yes, it's called simpledateformat. You just need to define your schema
Because you didn't (volunteer?) In a precise year, I added:
DateFormat df = new SimpleDateFormat("M'm'W'w'F'd'H'h'm'm's's'yyyy"); System.out.println(df.parse("5m1w5d3h10m15s"+"2012"));
Of course, some libraries are available (many people redirect to joda, which is better than standard and chaotic Java libraries), but your question is "if Java has a built-in way to parse time / date", the answer is a clear yes
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码