如何将MySQL的datetime类型转换为Java格式化日期?

2026-04-01 23:031阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计209个文字,预计阅读时间需要1分钟。

如何将MySQL的datetime类型转换为Java格式化日期?

以下是对原文的简化修改:

http://blog.sina.com.cn/s/blog_4953e9290100c2tz.,http://www.cnblogs.com/BearOcean/archive/2007/04/09/705751.,Java中格式化当前日期转为特定格式。

blog.sina.com.cn/s/blog_4953e9290100c2tz.html

www.cnblogs.com/BearOcean/archive/2007/04/09/705751.html

java中格式化当前日期并转成字符串

DateFormat formatter new

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

String datetime

formatter.format(new java.util.Date());

通过java向mysql中插入datetime

类型的数据

String sql "INSERT INTO wp_posts ( post_date )VALUES(?)";

PreparedStatement pstmt connection.prepareStatement(sql);

Timestamp time new Timestamp(System.currentTimeMillis());

pstmt.setTimestamp(1, time);

类似的有

pstmt.setDate(10, new java.sql.Date(System.currentTimeMillis()));

// 只有日期

如何将MySQL的datetime类型转换为Java格式化日期?

pstmt.setTime(11, new

Time(System.currentTimeMillis()));

// 只有时间

pstmt.setTimestamp(12, new Timestamp(System.currentTimeMillis()));

// 日期和时间

分享到

2009-07-23 09:37

浏览 4689

评论

本文共计209个文字,预计阅读时间需要1分钟。

如何将MySQL的datetime类型转换为Java格式化日期?

以下是对原文的简化修改:

http://blog.sina.com.cn/s/blog_4953e9290100c2tz.,http://www.cnblogs.com/BearOcean/archive/2007/04/09/705751.,Java中格式化当前日期转为特定格式。

blog.sina.com.cn/s/blog_4953e9290100c2tz.html

www.cnblogs.com/BearOcean/archive/2007/04/09/705751.html

java中格式化当前日期并转成字符串

DateFormat formatter new

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

String datetime

formatter.format(new java.util.Date());

通过java向mysql中插入datetime

类型的数据

String sql "INSERT INTO wp_posts ( post_date )VALUES(?)";

PreparedStatement pstmt connection.prepareStatement(sql);

Timestamp time new Timestamp(System.currentTimeMillis());

pstmt.setTimestamp(1, time);

类似的有

pstmt.setDate(10, new java.sql.Date(System.currentTimeMillis()));

// 只有日期

如何将MySQL的datetime类型转换为Java格式化日期?

pstmt.setTime(11, new

Time(System.currentTimeMillis()));

// 只有时间

pstmt.setTimestamp(12, new Timestamp(System.currentTimeMillis()));

// 日期和时间

分享到

2009-07-23 09:37

浏览 4689

评论