In PHP, you can use "SimpleDateFormat.format" to convert date into String, the syntax is "SimpleDateFormat.format("Time|Format")"; the usage of format is to convert the current time format into the specified format.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
How to convert date to string using php: you can use SimpleDateFormat.format converts date into String
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);
Recommended: "2021 PHP Interview Questions Summary (Collection)" "php video tutorial》
The above is the detailed content of How to convert date to string in php. For more information, please follow other related articles on the PHP Chinese website!