1. package com.ob;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. public class DateTest {
  7. public static void main(String[] args) throws ParseException {
  8. Calendar now = Calendar.getInstance();
  9. System.out.println("年: " + now.get(Calendar.YEAR));
  10. System.out.println("月: " + (now.get(Calendar.MONTH) + 1) + "");
  11. System.out.println("日: " + now.get(Calendar.DAY_OF_MONTH));
  12. System.out.println("时: " + now.get(Calendar.HOUR_OF_DAY));
  13. System.out.println("分: " + now.get(Calendar.MINUTE));
  14. System.out.println("秒: " + now.get(Calendar.SECOND));
  15. System.out.println("当前时间毫秒数:" + now.getTimeInMillis());
  16. System.out.println(now.getTime());
  17. Date d = new Date();
  18. System.out.println(d);
  19. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  20. String dateNowStr = sdf.format(d);
  21. System.out.println("格式化后的日期:" + dateNowStr);
  22. String str = "2012-1-13 17:26:33";  //要跟上面sdf定义的格式一样
  23. Date today = sdf.parse(str);
  24. System.out.println("字符串转成日期:" + today);
  25. }
  26. }
  27. 输出结果:

    年: 2012
    月: 1
    日: 13
    时: 17
    分: 28
    秒: 19
    当前时间毫秒数:1326446899902
    Fri Jan 13 17:28:19 CST 2012
    Fri Jan 13 17:28:19 CST 2012
    格式化后的日期:2012-01-13 17:28:19
    字符串转成日期:Fri Jan 13 17:26:33 CST 2012

最新文章

  1. [转]JVM调优总结:一些概念
  2. tar.xz文件如何解压
  3. Algorithmic Graph Drawing in TikZ
  4. svn服务器端的客户端自动更新
  5. jquery的常用的容易忘记的东西
  6. c#设计模式之单例模式
  7. C++ 里 构建动态二维数组
  8. 手机端的表单验证和PC端的不同
  9. QML Flipable、Flickable和状态与动画 下篇
  10. [AndroidTips]startService与bindService的区别
  11. 16.3Sum Closet
  12. 【转】mip-semi-fixed 走走又停停
  13. VUE 父组件与子组件交互
  14. MapReduce编程:数字排序
  15. pandas列操作集锦
  16. 关于标准的知识 GB ISO 等内容
  17. netMarketing类库: 类库说明
  18. 牛客多校第三场 A- PACM Team 背包/记忆路径
  19. k-center问题-学习
  20. 树莓派进阶之路 (025) - ubuntu下使用VNC连接树莓派raspberry(转)

热门文章

  1. Robot Framework学习笔记(一)------环境搭建
  2. Oracle死锁情况
  3. Atlas 安装报错 package Atlas-2.2.1-1.x86_64 is intended for a x86_64 architecture
  4. HTML知识点总结之div、section标签
  5. 常见的Linux 的命令
  6. python 最基本的的单例模型的实现及应用
  7. Keepalived概述和安装(1)
  8. Python_day1
  9. msfconsole弄外网手机木马
  10. JavaWeb(二)cookie与session的应用