php实现date转string的方法:可以利用simpledateformat.format把date转成string,如【str3 = format1.format(date1);】。
date与string格式的转换
(推荐教程:php视频教程)
simpledateformat.format把date转成string。
simpledateformat.parse把string转成date。
代码测试:
simpledateformat format1 = new simpledateformat("yyyy-mm-dd hh:mm:ss");simpledateformat format2 = new simpledateformat("yyyy年mm月dd日 hh时mm分ss秒");date date1 = null;date date2 = null;string str1 = "2009-02-14 12:00:00";string str2 = "2009年02月14日 12时00分00秒";// string转date:string 必须严格按照定义的格式try {date1 = format1.parse(str1);date2 = format2.parse(str2);} catch (parseexception ex) {logger.getlogger(main.class.getname()).log(level.severe, null, ex);}system.out.println("date1= "+date1);system.out.println("date2= "+date2);//date转stringstring str3 = null;string str4 = null;str3 = format1.format(date1);str4 = format2.format(date2);system.out.println("str1= "+str3);system.out.println("str2= "+str4);
相关推荐:php培训
以上就是php如何实现date转string的详细内容。