1 10 11 package org.mule.util; 12 13 import java.text.ParsePosition ; 14 import java.text.SimpleDateFormat ; 15 import java.util.Date ; 16 17 import org.mule.config.i18n.Message; 18 import org.mule.config.i18n.Messages; 19 20 24 public class DateUtils extends org.apache.commons.lang.time.DateUtils 26 { 27 28 public static String getTimeStamp(String format) 29 { 30 SimpleDateFormat formatter = new SimpleDateFormat (format); 32 Date currentTime = new Date (); 33 return formatter.format(currentTime); 34 } 35 36 public static String formatTimeStamp(Date dateTime, String format) 37 { 38 SimpleDateFormat formatter = new SimpleDateFormat (format); 40 return formatter.format(dateTime); 41 } 42 43 public static String getStringFromDate(Date date, String format) 44 { 45 SimpleDateFormat formatter = new SimpleDateFormat (format); 48 return formatter.format(date); 49 } 50 51 public static Date getDateFromString(String date, String format) 52 { 53 SimpleDateFormat formatter = new SimpleDateFormat (format); 56 ParsePosition pos = new ParsePosition (0); 57 58 return formatter.parse(date, pos); 60 } 61 62 public static String getFormattedDuration(long mills) 63 { 64 long days = mills / 86400000; 65 mills = mills - (days * 86400000); 66 long hours = mills / 3600000; 67 mills = mills - (hours * 3600000); 68 long mins = mills / 60000; 69 mills = mills - (mins * 60000); 70 long secs = mills / 1000; 71 mills = mills - (secs * 1000); 72 73 StringBuffer bf = new StringBuffer (60); 74 bf.append(days).append(" ").append(new Message(Messages.DAYS).getMessage()).append(", "); 75 bf.append(hours).append(" ").append(new Message(Messages.HOURS).getMessage()).append(", "); 76 bf.append(mins).append(" ").append(new Message(Messages.MINS).getMessage()).append(", "); 77 bf.append(secs).append(".").append(mills).append(" ").append(new Message(Messages.SEC).getMessage()); 78 return bf.toString(); 79 } 80 81 } 82 | Popular Tags |