09-09
25

JAVA时间比较

//获取系统当前时间  
SimpleDateFormat sdfTime = new SimpleDateFormat("kk:mm:ss");  
String nowTime = sdfTime.format(new Date());  
//获取时间中除冒号以外的其他值  
StringBuffer sba = new StringBuffer();  
//获取kk  
String astartTime = startTime.substring(0, 2);  
//获取mm  
String bstartTime = startTime.substring(3, 5);  
//获取ss  
String cstartTime = startTime.substring(6, 8);  
  
sba.append(astartTime);  
sba.append(bstartTime);  
sba.append(cstartTime);  
String dstartTime = sba.toString();  
//将系统时间转换为Int型  
int estartTime = Integer.parseInt(dstartTime);  
  
//测试时间  
textTime = "20:00:00";  
//通过上面的方法同样获得Int型的测试时间即:etextTime = 200000  
  
if(estartTime < etextTime)  
{  
   System.out.println("****estartTime < etextTime****");  
}  


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: 时间 时间差 比较
相关日志:
评论: 0 | 引用: 0 | 查看次数: 245
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭