/**
* Get the interval date by specified start date and time
* @param d the start date
* @param time the interval time
* @param isAfter count the after date,otherwise cout before date
* @return
*/
public static Date getIntervalTime(Date d,String time,boolean isAfter)
{
try
{
Calendar c = java.util.Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date dCount = sdf.parse(time);
c.setTime(d);
if(isAfter)
c.add(Calendar.SECOND,getSecondByTime(time));
else
c.add(Calendar.SECOND,0-getSecondByTime(time));
return c.getTime();
//System.out.println(dCount.getHours());
//System.out.println(dCount.getSeconds());
//System.out.println(dCount.getMinutes());
}catch(java.text.ParseException e)
{
throw new MFUtilException("Translate date time faield:" + time);
}
}
* Get the interval date by specified start date and time
* @param d the start date
* @param time the interval time
* @param isAfter count the after date,otherwise cout before date
* @return
*/
public static Date getIntervalTime(Date d,String time,boolean isAfter)
{
try
{
Calendar c = java.util.Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date dCount = sdf.parse(time);
c.setTime(d);
if(isAfter)
c.add(Calendar.SECOND,getSecondByTime(time));
else
c.add(Calendar.SECOND,0-getSecondByTime(time));
return c.getTime();
//System.out.println(dCount.getHours());
//System.out.println(dCount.getSeconds());
//System.out.println(dCount.getMinutes());
}catch(java.text.ParseException e)
{
throw new MFUtilException("Translate date time faield:" + time);
}
}
解决方案 »
- 再次求助兄弟们一个正则表达式.....
- java中怎么设置一个文件夹为只读 并且里面的文件也为也为只读
- getClass().getClassLoader() 返回 null
- 想问问关于private和final定义方法
- 有一个异常我不知道是什么意思。帮帮我。
- 关于java.util.zip的问题,主要是ZipEntry中getSize()返回值为-1。(附测试源码)
- <<开心辞典>>中的一题求解!
- 各位大侠请问:为什么无法使用java的AppletViewer
- 还是JDS的问题
- 怎样让changeFlag();调用flag?(多线程参与与不参与的两种情况)
- 关于inputstream的read方法的疑问
- 郁闷啊,自己觉得自己写的代码BUG太多了,大家教教我该怎么样避免这种情况。
* Get the seconds by the specified HH:mm:ss
*
* @param time the specified format time
*
* @return the total seconds.
*/
public static int getSecondByTime(String time)
{
StringTokenizer tok = new StringTokenizer(time, ":"); String HH = "";
if(tok.hasMoreTokens())
{
HH = tok.nextToken();
} String mm = "";
if(tok.hasMoreTokens())
{
mm = tok.nextToken();
} String ss = "";
if(tok.hasMoreTokens())
{
ss = tok.nextToken();
} int iHH = 0;
try{iHH = Integer.parseInt(HH);}
catch(Exception e){} int imm = 0;
try
{
imm = Integer.parseInt(mm);
}catch(Exception e){} int iss = 0;
try
{
iss = Integer.parseInt(ss);
}catch(Exception e){} int seconds = iHH * 3600 + imm * 60 + iss;
return seconds;
}
你set差1个小时,再get就又差了1个小时。而且Date(String s) 、parse(String s) 这2函数为Deprecated.最好不要在程序中使用。
行么?
我们还年轻牛奶会有的奶牛也会有的
可天天在 csdn 混这些会有吗 ??