PHP date string time synchronization

I am trying to parse a combination of date and date and time strings and would like to know if there is a more sensible way

Data examples

9/3/2013 8:50:05 AM 9/4/2013 1:42:28 PM 9/11/2013 12:01:21 PM .... 

Here is what I do .. Looking through the list of Date Time strings

  <?php $x = "9/3/2013 8:50:05 AM" $ExDt = str_getcsv(trim($x," "); $ExDate = $ExDt[0]; $ExTm = $ExDt[1] . " " . $ExDt[2]; $ExTime = date("H:i:s", strtotime($ExTm)); // Change to 24 hour format echo $ExDate; echo $ExTime; ?> 
+6
source share
4 answers

I feel a safer conversion with this (timezone is not taken into account in the example)

 $start = '25/12/2013 10:13:46'; $new_date = DateTime::createFromFormat('d/m/YH:i:s', $start); echo $new_date->format('Ymd H:i:s'); 
+7
source
 $dt = new DateTime('9/3/2013 8:50:05 AM'); echo $dt->format('m/d/Y'); echo $dt->format('H:i:s'); 
+2
source
 $time = strtotime('9/3/2013 8:50:05 AM'); echo date('H:i:s',$time); // 08:50:05 echo date('Ym-d',$time); // 2013-03-09 
+1
source
 <?php $x = "9/3/2013 8:50:05 AM"; $time = strtotime($x); echo date('m/d/Y', $time), "\n"; echo date('H:i:s', $time), "\n"; 

See the result here.

more about date format

0
source

Source: https://habr.com/ru/post/954553/


All Articles