java.sql.Timestamp 类的使用

 时间:2026-02-13 14:53:23

1、 获取当前时间:

第一种:

 Timestamp nowdate1 = new Timestamp(System.currentTimeMillis());

  System.out.println("System.currentTimeMillis():"+nowdate1);

第二种:

  Date date = new Date();   

      Timestamp nowdate2 = new Timestamp(date.getTime());

  System.out.println("new Date():"+nowdate2)


java.sql.Timestamp 类的使用

2、 把 String类型转换 Timestamp:

  String datestr = "2002-01-29 04:37:21.453";

  Timestamp ts = Timestamp.valueOf(datestr);

  System.out.println(ts);

java.sql.Timestamp 类的使用

3、 把 Timestamp 类型转换 String:

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  Timestamp nowdate = new Timestamp(System.currentTimeMillis());

  String datestr = sdf.format(nowdate);

  System.out.println(datestr);

java.sql.Timestamp 类的使用

  • C#中如何判断字符串是否可以转换为数字?
  • android设置背景图片
  • NX 10.0怎么开启将剖面线角度限制在45度
  • IntelliJ IDEA怎么关闭显示文件扩展名
  • VC++6.0提示无法执行程序如何解决
  • 热门搜索
    三亚免税店攻略 标致308怎么样 青岛简介 人应该怎么活 我的世界铁门怎么做 拉肚子会减肥吗 冰箱有异味怎么去除 红烧羊肉的做法视频 绾青丝简介 针织衫怎么搭配