java时间方面的知识点
来源:互联网 发布:经典java编程面试题 编辑:程序博客网 时间:2024/05/22 22:18
延时
Thread.sleep(10000); //单位ms
获取系统时间戳用来计时
long start = System.currentTimeMillis();//返回当前系统时间(自1970年),单位:毫秒 测试代码 long end = System.currentTimeMillis(); long costTime = end - start; System.out.println("cost: " + costTime + "ms");
(粗略计时,不考虑系统的繁忙)
时间戳转换成日期时间
long time = System.currentTimeMillis(); //(粗略计时,不考虑系统的繁忙)SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //yyyy-MM-dd hh:mm:ssString date = sdf.format(new Date(time)); // Date(毫秒数)System.out.println(date);
将毫秒转换成天、小时、分钟、秒
/** * 将毫秒转换成小时、分钟、秒(是否可以输出毫秒?) * @param time 毫秒 */public static String ms2HHMMSS(long time) {long milliseconds = time % 1000; //毫秒long seconds = Math.round(time / 1000.0);long minutes = seconds / 60;seconds %= 60;long hours = minutes / 60;minutes %= 60;long days = hours / 24;hours %= 24;StringBuilder timeReport = new StringBuilder();timeReport.append("\nTotal time: ");if (days != 0) {timeReport.append(days);timeReport.append(" days ");}if (hours != 0) {timeReport.append(hours);timeReport.append(" hours ");}if (minutes != 0) {timeReport.append(minutes);timeReport.append(" minutes ");}if(seconds !=0){timeReport.append(seconds);timeReport.append(" seconds ");}timeReport.append(milliseconds);timeReport.append(" ms");//System.out.println(timeReport);return timeReport.toString();}
JAVA如何插入MySql的datetime类型
使用java Timestamp类型
Date date = new Date();Timestamp timeStamp = new Timestamp(date.getTime());// tb_blessing(id,sender, receiver, content,time);dd.insert("insert into tb_blessing(sender, receiver, content,time)" + " values(? , ? , ?, ?)",getSender(), getReceiver(), getContent(), timeStamp);
0 0
- java时间方面的知识点
- JAVA基础方面知识点
- JDBC方面的知识点
- Tomcat方面的知识点
- linux时间方面的设置
- Android中多线程下载方面的知识点
- Android中活动Activity方面的知识点
- 整理关于JVM方面的知识点
- 整理关于JVM方面的知识点
- 安卓绘制方面的零散知识点
- hashMap和hashtable方面的知识点小结
- java方面的书籍
- Java方面的好书
- 最近看到的一些JAVA方面的参考书,有时间下载回来看
- 关于android时间方面的知识
- 内存管理方面知识点
- 操作系统 网络方面知识点
- 关于文字编码方面的知识点的一些整理
- Marvin_wu-嵌入式 - fpga-DSP领域
- Eclipse搭建Struts2
- 启动受管Server报错,自己犯了弱智问题
- http://blog.csdn.net/huanghuanghbc/article/details/9357629
- 我的技术路线小结2(2011-2014)
- java时间方面的知识点
- wgwg
- TNS-12541: TNS:no listener
- 软件项目开发团队组员跨项目组兼职案例分析
- wegwg
- JAVA的四种引用
- 最大连续子序列
- 关于Python中的for循环控制语句
- 编译小米2s CyanogenMod 版本遇到的几个问题 (02.26更新)