Created
December 28, 2018 02:10
-
-
Save jesselima/37796230b3fc6b744d660f5d709e88ef to your computer and use it in GitHub Desktop.
Format String to String Dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.bank.bankapp.shared; | |
/** | |
* Created by jesse on 12/28/18. | |
* This is a part of the project BankApp. | |
*/ | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.Locale; | |
public final class DateUtils { | |
/** | |
* Allows others classes instantiates a empty DateUtils object. | |
*/ | |
public DateUtils() { | |
} | |
/** | |
* This method when called receives a date as String format in this pattern: yyyy-MM-dd'T'HH:mm:ss | |
* and return a date as a String object with this pattern: HH:mm LLL dd, yyyy | |
* | |
* @param dateString is the date in a string format is this pattern yyyy-MM-dd'T'HH:mm:ss | |
* @return the date as a string with this new format. | |
*/ | |
public static String formatStringDate(String dateString) { | |
String dateStringFormated = null; | |
Date date; | |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); | |
try { | |
date = dateFormat.parse(dateString); | |
dateStringFormated = formatDate(date); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
return dateStringFormated; | |
} | |
/** | |
* This method receives the Date object as input parameter. | |
* | |
* @param dateObject is the Date object to be formated. | |
* @return a String object with the date formated according to the SimpleDateFormat method pattern: HH:mm LLL dd, yyyy. | |
*/ | |
private static String formatDate(Date dateObject) { | |
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH); | |
return dateFormat.format(dateObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment