实例讲解String Date Calendar之间的转换
程序员文章站
2023-12-19 10:52:04
1.calendar 转化 string
calendar calendat = calendar.getinstance();
simpledatefor...
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);
以上这篇实例讲解string date calendar之间的转换就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。