JAVA 时间工具类
package org.loushang.workflow.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.loushang.next.i18n.ResourceBundle;
import org.loushang.workflow.engine.common.BspAddDate;
public class TimeUtils
{
public TimeUtils()
{
}
public static String getCurrentDateTime()
{
return sdf.format(Calendar.getInstance().getTime());
}
public static String getCurrentDate()
{
return sdf.format(Calendar.getInstance().getTime());
}
public static String formatTime(long l)
{
return sdf.format(new Date(l));
}
public static long parseLong(String s)
{
long l = 0L;
if(s != null && !"".equals(s))
try
{
Date date = sdf.parse(s);
l = date.getTime();
}
catch(ParseException parseexception) { }
return l;
}
public static long calcTimeDiff(String s, String s1)
{
return parseLong(s1) - parseLong(s);
}
public static String convertMillsTimeDiffToDisplayTimeStr(long l)
{
long l1 = 0L;
long l2 = 0L;
long l3 = 0L;
long l4 = 0L;
boolean flag = false;
boolean flag1 = false;
l /= 1000L;
l1 = l / 86400L;
l2 = l / 3600L - l1 * 24L;
l3 = l / 60L - l1 * 1440L - l2 * 60L;
l4 = l - l1 * 86400L - l2 * 3600L - l3 * 60L;
StringBuffer stringbuffer = new StringBuffer();
if(l1 > 0L)
{
stringbuffer.append(l1);
stringbuffer.append(ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.006", "\u5929"));
flag = true;
}
if(l2 > 0L || l2 == 0L && flag)
{
stringbuffer.append(l2);
stringbuffer.append(ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.007", "\u5C0F\u65F6"));
flag1 = true;
}
if(l3 > 0L || l3 == 0L && flag1)
{
stringbuffer.append(l3);
stringbuffer.append(ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.008", "\u5206"));
}
if(l4 >= 0L)
{
stringbuffer.append(l4);
stringbuffer.append(ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.009", "\u79D2"));
}
return stringbuffer.toString();
}
public static long getLimitTime(String s, String s1, int i)
{
BspAddDate bspadddate = new BspAddDate();
return bspadddate.getBspDateTime(s1, new Date(parseLong(s)), i);
}
public static long getWarnTime(String s, String s1, int i, int j)
{
BspAddDate bspadddate = new BspAddDate();
return bspadddate.getBspDateTime(s1, new Date(parseLong(s)), i - j);
}
public static String getLimitTimeStr(int i, String s)
{
StringBuffer stringbuffer = new StringBuffer();
stringbuffer.append(i);
String s1 = "";
if("Y".equals(s))
s1 = ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.010", "\u5E74");
else
if("M".equals(s))
s1 = ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.011", "\u6708");
else
if("D".equals(s))
s1 = ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.006", "\u5929");
else
if("h".equalsIgnoreCase(s))
s1 = ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.007", "\u5C0F\u65F6");
else
if("m".equals(s))
s1 = ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.008", "\u5206");
else
if("s".equals(s))
s1 = ResourceBundle.getPackageBundle("bpm.common").getLocaleMsg("BPM.COMMON.009", "\u79D2");
stringbuffer.append(s1);
return stringbuffer.toString();
}
public static long getLimitTimeInt(int i, String s)
{
long l = 0L;
if("Y".equals(s))
l = i * 365 * 24 * 60 * 60 * 1000;
else
if("M".equals(s))
l = i * 30 * 24 * 60 * 60 * 1000;
else
if("D".equals(s))
l = i * 24 * 60 * 60 * 1000;
else
if("h".equalsIgnoreCase(s))
l = i * 60 * 60 * 1000;
else
if("m".equals(s))
l = i * 60 * 1000;
else
if("s".equals(s))
l = i * 1000;
return l;
}
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
}
浙公网安备 33010602011771号