suppose there is a time_string like: "wallclock(2011-09-22T01:52:00)"
in C language, I can use "strptime(time_string, "wallclock(%Y-%m-%dT%H:%M:%S)", &tm)“
to get date time and store it into the struct tm,
and then use mktime(&tm) to get the date in seconds
But in Java, I find no way about how to transfer string "wallclock(2011-09-22T01:52:00)",
is there any way to do this job? thank you 🙂
You can either use
SimpleDateFormat:(Note that you probably want to set the time zone of
formatappropriately.)Or preferrably (IMO) use Joda Time to do the parsing:
This will parse to a
LocalDateTimewhich doesn’t have a time zone.In Java 8, you’d use
java.time.format.DateTimeFormatterinstead.