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:妹妹:ss"); SimpleDateFormat format2 = new SimpleDateFormat("yyyy年MM月dd日 HH时妹妹分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的具体内容,更多请存眷资源魔其它相干文章!
标签: php php教程 date php故障解决 php使用问题 string
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!