PHP Date And Time Functions In Hindi


पिछले Topic में हमने  PHP में date / time के बारे में पढ़ा , इस topic  में  हम PHP में Generally use होने  वाले date / time functions के बारे में पढ़ेंगे।


PHP हमें ऐसे बहुत से predefined functions provide करती है जिनका use करके हम date / time को आसानी से handle कर सकते हैं।

  1. date_default_timezone_set(timezone)
  2. checkdate(int $month, int $day, $year)
  3. getdate()
  4. strtotime($date or $time)
  5. time()
  6. date_default_timezone_set

PHP date_default_timezone_set Function

date_default_timezone_set() function default timezone set करने के लिए उसे किया जाता है , आप अपने timezone के हिसाब से सेट कर सकते हैं।

File : date_time_fun.php

Copy Fullscreen Close Fullscreen
<?php
  date_default_timezone_set('Asia/Kolkata');
  echo "Current Date Time : ".date("d/M/Y h:i:s A");
?>
Output
Current Date Time : 11/Sep/2020 06:22:00 PM

PHP checkdate Function

checkdate() function check करता है कि दी गयी date valid है या नहीं।

File : date_time_fun1.php

Copy Fullscreen Close Fullscreen
<?php
  if(checkdate(12,31, 2303))
    echo "Date is Valid";
  else
    echo "Date is Not valid";
?>
Output
Date is Valid

PHP getdate Function

getdate() function हमें date - time information का एक array return करता है।

File : date_time_fun2.php

Copy Fullscreen Close Fullscreen
<?php
  echo"<pre>";
  print_r(getdate());
?>
Output
Array
(
    [seconds] => 12
    [minutes] => 47
    [hours] => 17
    [mday] => 11
    [wday] => 5
    [mon] => 9
    [year] => 2020
    [yday] => 254
    [weekday] => Friday
    [month] => September
    [0] => 1599826632
)

PHP strtotime Function

strtotime() function , किसी English textual date time को UNIX timestamp में convert करता है ।

File : date_time_fun4.php

Copy Fullscreen Close Fullscreen
<?php
  $timestamp = strtotime('2020-12-12');
echo "Timestamp Format : $timestamp";
echo "After Change : ".date('Y-M-d', $timestamp);
/* we can also use now inside strtotime() function*/
echo "Current Date Time : " .date('d-M-Y h:i:s A', strtotime('now')); ?>
Output
Timestamp Format : 1607711400
After Change : 2020-Dec-12
Current Date Time : 11-Sep-2020 06:15:19 PM

PHP time Function

time() function , current UNIX timestamp return करता है जिसे हम strtotime() function() का use करके readable form में change कर सकते हैं।

File : date_time_fun5.php

Copy Fullscreen Close Fullscreen
<?php
  $time_stamp = time();
  echo "In Timestamp Format : $time_stamp";
  echo "After change : ".date('h:i:s a', strtotime($time_stamp));
?>
Output
In Timestamp Format : 1599826034
After change : 05:30:00 am

PHP date_default_timezone_get Function

date_default_timezone_get() function , current default timezone return करता है।  

File : date_time_fun6.php

Copy Fullscreen Close Fullscreen
<?php
  echo date_default_timezone_get();
?>
Output
Asia/Kolkata

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 4.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook