Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get a String with a detailed formatted date and time
- *
- * @param date The instance of the class Date (with time)
- * @param language The l10n language in the two-char ISO format
- * @param shortDate A flag indicating whether to return short date details.
- * If set to true, the formatted string includes a shorter version of the date,
- * with abbreviated day of the week and month.
- * If set to false, the complete date information with full day of the week and month is included.
- * @return The string with the formatted date and time
- */
- public String getLocalizedDetailedDateTimeString(Date date, String language, Boolean shortDate){
- return getLocalizedDetailedDateTimeString(date, language, shortDate, true);
- }
- /**
- * Get a String with a detailed formatted date
- *
- * @param date The instance of the class Date (with time)
- * @param language The l10n language in the two-char ISO format
- * @param shortDate A flag indicating whether to return short date details.
- * If set to true, the formatted string includes a shorter version of the date,
- * with abbreviated day of the week and month.
- * If set to false, the complete date information with full day of the week and month is included.
- * @return The string with the formatted date
- */
- public String getLocalizedDetailedDateString(Date date, String language, Boolean shortDate){
- return getLocalizedDetailedDateTimeString(date, language, shortDate, false);
- }
- private String getLocalizedDetailedDateTimeString(Date date, String language, Boolean hasShortDate, Boolean hasTime){
- if (date == null) {
- return "";
- }
- if (language == null || !language.equals(LANG_PT)) {
- language = LANG_EN;
- }
- SimpleDateFormat dayFormat = new SimpleDateFormat(DATE_FORMAT_DAY);
- SimpleDateFormat yearAndTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT_YEAR_AND_TIME);
- SimpleDateFormat yearFormat = new SimpleDateFormat(DATE_FORMAT_YEAR);
- String dayOfWeek;
- String month;
- if (hasShortDate != null && hasShortDate){
- dayOfWeek = getLocalizedDayOfWeekFromDateShort(date, language);
- month = getLocalizedMonthFromDateShort(date, language);
- } else {
- dayOfWeek = getLocalizedDayOfWeekFromDate(date, language);
- month = getLocalizedMonthFromDate(date, language);
- }
- return dayOfWeek + ", " + (language.equals(LANG_PT) ?
- (dayFormat.format(date) + " " + Character.toUpperCase(month.charAt(0)) + month.substring(1)) :
- (Character.toUpperCase(month.charAt(0)) + month.substring(1) + " " + dayFormat.format(date)))
- + " " + ((hasTime) ? yearAndTimeFormat.format(date) : yearFormat.format(date));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement