atitit.标准时间格式 互相转换 秒数 最佳实践
2014-07-17 00:12
417 查看
atitit.标准时间格式 互相转换 秒数 最佳实践
例如00:01:19 转换为秒数 79,,and互相转换
一个思路是使用div 60 mod...不过麻烦的...
更好的方法是使用stamp
...
前台添加个日期,使用时间戳来计算...
作者:: 老哇的爪子 Attilax 艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://blog.csdn.net/attilax
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
String s="00:01:09";
int sec=str2secs(s); //69
System.out.println(sec);
sec=79; //00:01:19
System.out.println(secs2str(sec));
}
private static String secs2str(int sec) throws ParseException {
String date="2014-01-01";
Date start= DateUtil.str2date_excpt(date+" 00:00:00", true);
long endTimestamp = sec*1000+start.getTime();
Date end=new Date(endTimestamp);
String s=DateUtil.date2str(end, true);
String[] sa=s.split(" ");
return sa[1];
}
private static int str2secs(String s) throws ParseException {
String date="2014-01-01";
String full=date+" "+s;
Date dt= DateUtil.str2date_excpt(full, true);
Date dt2= DateUtil.str2date_excpt(date+" 00:00:00", true);
int i=DateUtil.getSecondInterval(dt2, dt);
return i;
}
参考
paip.日期时间操作以及时间戳uapi php java python 总结 - attilax的专栏 - 博客频道 - CSDN.NET.htm
例如00:01:19 转换为秒数 79,,and互相转换
一个思路是使用div 60 mod...不过麻烦的...
更好的方法是使用stamp
...
前台添加个日期,使用时间戳来计算...
作者:: 老哇的爪子 Attilax 艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://blog.csdn.net/attilax
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
String s="00:01:09";
int sec=str2secs(s); //69
System.out.println(sec);
sec=79; //00:01:19
System.out.println(secs2str(sec));
}
private static String secs2str(int sec) throws ParseException {
String date="2014-01-01";
Date start= DateUtil.str2date_excpt(date+" 00:00:00", true);
long endTimestamp = sec*1000+start.getTime();
Date end=new Date(endTimestamp);
String s=DateUtil.date2str(end, true);
String[] sa=s.split(" ");
return sa[1];
}
private static int str2secs(String s) throws ParseException {
String date="2014-01-01";
String full=date+" "+s;
Date dt= DateUtil.str2date_excpt(full, true);
Date dt2= DateUtil.str2date_excpt(date+" 00:00:00", true);
int i=DateUtil.getSecondInterval(dt2, dt);
return i;
}
参考
paip.日期时间操作以及时间戳uapi php java python 总结 - attilax的专栏 - 博客频道 - CSDN.NET.htm
相关文章推荐
- atitit.标准时间格式 互相转换 秒数 最佳实践
- atitit.标准时间格式 相互转换 秒数 最佳实践
- atitit.文件上传带进度条的实现原理and组件选型and最佳实践总结O7
- atitit.表格的绑定client side 最佳实践
- Atitit. Gui控件and面板----程序快速启动区--最佳实践Launchy ObjectDock-o0g
- atitit.人脸识别的应用场景and使用最佳实践 java .net php
- atitit.文件上传带进度条的实现原理and组件选型and最佳实践总结O7
- Atitit.guice3 ioc 最佳实践 o9o
- atitit.提升兼容性最佳实践 o9o
- Atitit. 最佳实践 QA----降低cpu占有率--cpu占用太高怎么办
- Atitit. 最佳实践 QA----减少cpu占有率--cpu占用太高怎么办
- atitit.导航的实现最佳实践and声明式编程
- atitit.避免NullPointerException 总结and 最佳实践 o99
- Atitit. js mvc 总结(2)----angular 跟 Knockout o99 最佳实践
- atitit.提升兼容性最佳实践 o9o
- atitit.导航的实现最佳实践and声明式编程
- atitit.ajax 最佳实践跟框架选型 o99
- atitit.泛型编程总结最佳实践 vO99 java c++ c#.net php
- atitit.避免NullPointerException 总结and 最佳实践 o99
- atitit.人脸识别的应用场景and使用最佳实践 java .net php