Skip to content

Instantly share code, notes, and snippets.

@sasajib
Forked from jimjam88/convert-date.java
Last active August 29, 2015 14:08
Show Gist options
  • Save sasajib/0447883497309c150bdd to your computer and use it in GitHub Desktop.
Save sasajib/0447883497309c150bdd to your computer and use it in GitHub Desktop.
// Imports required
import java.text.SimpleDateFormat;
import java.text.ParseException;
/**
* Convert a date to a different format.
*
* @param currentFormat The current date format
* @param newFormat The new date format
* @param subject The date that's going to be converted
* @return The new data as a string
* @throws ParseException If the conversion fails (Invalid date format)
*/
final public static String convertDate(String currentFormat, String newFormat, String subject)
throws ParseException
{
return new SimpleDateFormat(newFormat).format(
new SimpleDateFormat(currentFormat).parse(subject)
).toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment