zoukankan      html  css  js  c++  java
  • 【Java】【9】String Date Calendar之间的转换

    前言:

    1, Calendar 转化 String

    2, Calendar 转化 Date

    3,Date 转化 String

    4,Date 转化 Calendar

    5,String 转化 Calendar

    6,String 转化 Date

    7,Date 转化 TimeStamp

    8,String 转化 TimeStamp

    正文:

    1, Calendar 转化 String

    Calendar calendat = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String dateStr = sdf.format(calendar.getTime());

    2, Calendar 转化 Date

    Calendar calendar = Calendar.getInstance();
    Date date = calendar.getTime();

    3,Date 转化 String

    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String dateStr = sdf.format(date);

    4,Date 转化 Calendar

    Date date = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    5,String 转化 Calendar

    String str = "2012-5-27";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(str);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    6,String 转化 Date

    String str = "2012-5-27";
    SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
    Date date= sdf.parse(str);

    7,Date 转化 TimeStamp

    Date date = new Date();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String time = df.format(date);
    Timestamp ts = Timestamp.valueOf(time);

    8,String 转化 TimeStamp

    Timestamp ts = Timestamp.valueOf("2012-1-14 08:11:00");

    参考博客:

    1,[java]转:String Date Calendar之间的转换 - 祺祺怪怪的 - 博客园
    https://www.cnblogs.com/qima/p/3652566.html

  • 相关阅读:
    使用Stream流递归 组合树形结构
    MySQL 8 通用表表达式
    sa-token 权限认证
    先更新缓存还是先更新数据库?
    钉钉 回调事件 消息加解密
    commons-io
    stream和parallelstream的区别
    消除if...else
    springboot 扩展xml请求和响应
    springboot admin 邮箱
  • 原文地址:https://www.cnblogs.com/huashengweilong/p/10724466.html
Copyright © 2011-2022 走看看