php new datetime createfromformat | Exam-Lib
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
Welcome to our Education website, plz like our page facebook to support us. Thank You and wish you good navigation

php new datetime createfromformat

abdelouafiApr 22, 2018

    1. abdelouafi

      abdelouafi Administrator Staff Member

      Messages:
      617
      Likes Received:
      13
      Trophy Points:
      18
      Joined
      Sep 13, 2016
      DateTime::createFromFormat: Analyse une chaîne de temps selon un format spécifié

      Description:
      public static DateTime DateTime::createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] )


      Exemple 1: Le style orienté objet

      Code:
      <?php
      $date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
      echo $date->format('Y-m-d');
      ?>
      Exemple 2: Le style procédural

      Code:
      <?php
      $date = date_create_from_format('j-M-Y', '15-Feb-2009');
      echo date_format($date, 'Y-m-d');
      ?>
      Exemple 3:
      Code:
      <?php
      echo 'Current time: ' . date('Y-m-d H:i:s') . "\n";
      
      $format = 'Y-m-d';
      $date = DateTime::createFromFormat($format, '2009-02-15');
      echo "Format: $format; " . $date->format('Y-m-d H:i:s') . "\n";
      
      $format = 'Y-m-d H:i:s';
      $date = DateTime::createFromFormat($format, '2009-02-15 15:16:17');
      echo "Format: $format; " . $date->format('Y-m-d H:i:s') . "\n";
      
      $format = 'Y-m-!d H:i:s';
      $date = DateTime::createFromFormat($format, '2009-02-15 15:16:17');
      echo "Format: $format; " . $date->format('Y-m-d H:i:s') . "\n";
      
      $format = '!d';
      $date = DateTime::createFromFormat($format, '15');
      echo "Format: $format; " . $date->format('Y-m-d H:i:s') . "\n";
      ?>
       
      Loading...

Share This Page

Share