当前位置: 移动技术网 > IT编程>开发语言>Java > 实例讲解String Date Calendar之间的转换

实例讲解String Date Calendar之间的转换

2019年07月19日  | 移动技术网IT编程  | 我要评论

我速购,中国牧羊犬俱乐部,张智霖的儿子

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之间的转换就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网