Well, that's what java.text.DateFormat
is for (and particularly its SimpleDateFormat
subclass) - but personally I would suggest that you use Joda Time instead.
In particular Joda Time's DateTimeFormatter
class is thread-safe, unlike SimpleDateFormat
- so you can create a single instance with the appropriate pattern, and use it from any thread. Additionally, the DateTimeFormat
class acts as a factory with lots of preset patterns in ISODateFormat
. Oh, and controlling the time zone etc is rather better with Joda Time.
Finally, Joda Time is simply a better date and time API. It's not perfect, but it's much better than the built-in Date
and Calendar
support in Java.
EDIT: Trying to parse your sample string, I'm having trouble with the "BST" bit... partly because that's not really a full time zone (it's just the DST part of the Europe/London time zone) and partly because I can't quite get Joda Time to do what I want... it looks like in this one case, SimpleDateFormat
wins out :(