How can I take a string in a format such as: 2008-06-02 00:00:00.0 and convert it to: 02-Jun-2008?
Can I somehow take the original string, convert it to a Date object, then use a formatter to get the final output (rather than parsing the string myself)? Thanks!
You can use
SimpleDateFormatto convert between aStringand aDateobject and vice versa based on a pattern. Click the API link, you’ll see patterns being explained in detail. A 4-digit year can be represented withyyyy, a 3-character month abbreviation can be represented withMMMand so on.First you need to parse the
Stringof the first format into aDateobject:Then you need to format the
Dateinto aStringof the second format:Note that you need to take the
Localeinto account as well to get the month to be printed in English, else it will use the platform’s default locale to translate the month.