• [java]转:String Date Calendar之间的转换


    1.Calendar 转化 String

    Calendar calendat = Calendar.getInstance();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    String dateStr = sdf.format(calendar.getTime());

    2.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);

    3.Date 转化String

    SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");

    String dateStr=sdf.format(new Date());

    4.String 转化Date

    String str="2012-5-27";

    SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");

    Date date= sdf.parse(str);

    5.Date 转化Calendar

    Calendar calendar = Calendar.getInstance();

    calendar.setTime(new java.util.Date());

    6.Calendar转化Date

    Calendar calendar = Calendar.getInstance();

    java.util.Date date =calendar.getTime();

    7.String 转成 Timestamp

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

    8.Date 转 TimeStamp

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

    String time = df.format(new Date());

    Timestamp ts = Timestamp.valueOf(time);

    转自:http://www.cnblogs.com/qima/p/3652566.html

  • 相关阅读:
    Stm32高级定时器(一)
    AES算法简介
    vsim仿真VHDL输出fsdb格式文件
    ncsim仿真VHDL
    云贵高原骑行
    触发器(笔记)
    几种常见的十进制代码(笔记)
    时序电路分类
    组合逻辑电路和时序逻辑电路比较
    数字电路基础(网络整理)
  • 原文地址:https://www.cnblogs.com/symbol8888/p/7240513.html
Copyright © 2020-2023  润新知