@@ -251,7 +251,7 @@ else if (style.equals(DateTimeStyle.MEDIUM))
251251 }
252252 else if (style .equals (DateTimeStyle .SHORT ))
253253 {
254- pattern = "MMM dd, yyyy " ;
254+ pattern = "MM/dd/yy " ;
255255 }
256256 else
257257 {
@@ -315,7 +315,10 @@ public static String formatWithStyle(String date, DateTimeStyle style)
315315 * @see DateTimeFormat#TIME_PATTERN_1
316316 * @param date Date object
317317 * @return Time String
318- */
318+ *
319+ * @deprecated Use {@link #extractTimeFromDate(Date, boolean)} method instead
320+ **/
321+ @ Deprecated
319322 public static String formatTime (Date date , boolean forceShowHours )
320323 {
321324 SimpleDateFormat iso8601Format = new SimpleDateFormat (DateTimeFormat .TIME_PATTERN_1 , Locale .getDefault ());
@@ -338,7 +341,10 @@ public static String formatTime(Date date, boolean forceShowHours)
338341 * Extract time from date without seconds
339342 * @param date Date object
340343 * @return Time string
341- */
344+ *
345+ * @deprecated use {@link #extractTimeFromDate(String, boolean)} method instead
346+ **/
347+ @ Deprecated
342348 public static String formatTime (String date , boolean forceShowHours )
343349 {
344350 return formatTime (formatStringToDate (date ),forceShowHours );
@@ -348,7 +354,10 @@ public static String formatTime(String date, boolean forceShowHours)
348354 * Extract time from date without seconds
349355 * @param date Date object
350356 * @return Time string
351- */
357+ *
358+ * @deprecated use {@link #extractTimeFromDate(Date)} method instead
359+ **/
360+ @ Deprecated
352361 public static String formatTime (Date date )
353362 {
354363 return formatTime (date ,false );
@@ -358,12 +367,70 @@ public static String formatTime(Date date)
358367 * Extract time from date without seconds
359368 * @param date Date object
360369 * @return Time string
361- */
370+ *
371+ * @deprecated use {@link #extractTimeFromDate(String)} method instead
372+ **/
373+ @ Deprecated
362374 public static String formatTime (String date )
363375 {
364376 return formatTime (date ,false );
365377 }
366378
379+ /**
380+ * Extract time from date without seconds
381+ * @see DateTimeFormat#TIME_PATTERN_1
382+ * @param date Date object
383+ * @return Time String
384+ *
385+ **/
386+ public static String extractTimeFromDate (Date date , boolean forceShowHours )
387+ {
388+ SimpleDateFormat iso8601Format = new SimpleDateFormat (DateTimeFormat .TIME_PATTERN_1 , Locale .getDefault ());
389+ iso8601Format .setTimeZone (TimeZone .getTimeZone (timeZone ));
390+ String time = iso8601Format .format (date );
391+ String [] hhmmss = time .split (":" );
392+
393+ int hours = Integer .parseInt (hhmmss [0 ]);
394+ int minutes = Integer .parseInt (hhmmss [1 ]);
395+ int seconds = Integer .parseInt (hhmmss [2 ]);
396+
397+ return (hours == 0 && !forceShowHours ? "" : hours < 10 ? String .valueOf ("0" + hours )+":" :
398+ String .valueOf (hours )+":" ) +
399+ (minutes == 0 ? "00" : minutes < 10 ? String .valueOf ("0" + minutes ) :
400+ String .valueOf (minutes ))+":"
401+ + (seconds == 0 ? "00" : seconds < 10 ? String .valueOf ("0" + seconds ): String .valueOf (seconds ));
402+ }
403+
404+ /**
405+ * Extract time from date without seconds
406+ * @param date Date object
407+ * @return Time string
408+ */
409+ public static String extractTimeFromDate (String date , boolean forceShowHours )
410+ {
411+ return extractTimeFromDate (formatStringToDate (date ),forceShowHours );
412+ }
413+
414+ /**
415+ * Extract time from date without seconds
416+ * @param date Date object
417+ * @return Time string
418+ */
419+ public static String extractTimeFromDate (Date date )
420+ {
421+ return extractTimeFromDate (date ,false );
422+ }
423+
424+ /**
425+ * Extract time from date without seconds
426+ * @param date Date object
427+ * @return Time string
428+ */
429+ public static String extractTimeFromDate (String date )
430+ {
431+ return extractTimeFromDate (date ,false );
432+ }
433+
367434 /**
368435 * Convert millis to human readable time
369436 *
@@ -381,8 +448,8 @@ public static String millisToTime(long millis)
381448
382449 long hours = TimeUnit .MILLISECONDS .toHours (millis );
383450
384- return (hours == 0 ? "" : hours < 10 ? String .valueOf ("0" + hours )+ ":" :
385- String .valueOf (hours )+ ":" ) +
451+ return (hours == 0 ? "" : hours < 10 ? String .valueOf ("0" + hours ) + ":" :
452+ String .valueOf (hours ) + ":" ) +
386453 (minutes == 0 ? "00" : minutes < 10 ? String .valueOf ("0" + minutes ) :
387454 String .valueOf (minutes )) + ":"
388455 + (seconds == 0 ? "00" : seconds < 10 ? String .valueOf ("0" + seconds )
0 commit comments