If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
पिछले Topic में हमने PHP में date / time के बारे में पढ़ा , इस topic में हम PHP में Generally use होने वाले date / time functions के बारे में पढ़ेंगे।
PHP हमें ऐसे बहुत से predefined functions provide करती है जिनका use करके हम date / time को आसानी से handle कर सकते हैं।
date_default_timezone_set() function default timezone set करने के लिए उसे किया जाता है , आप अपने timezone के हिसाब से सेट कर सकते हैं।
File : date_time_fun.php
<?php
date_default_timezone_set('Asia/Kolkata');
echo "Current Date Time : ".date("d/M/Y h:i:s A");
?>
checkdate() function check करता है कि दी गयी date valid है या नहीं।
File : date_time_fun1.php
<?php
if(checkdate(12,31, 2303))
echo "Date is Valid";
else
echo "Date is Not valid";
?>
getdate() function हमें date - time information का एक array return करता है।
File : date_time_fun2.php
<?php
echo"<pre>";
print_r(getdate());
?>
Array ( [seconds] => 12 [minutes] => 47 [hours] => 17 [mday] => 11 [wday] => 5 [mon] => 9 [year] => 2020 [yday] => 254 [weekday] => Friday [month] => September [0] => 1599826632 )
strtotime() function , किसी English textual date time को UNIX timestamp में convert करता है ।
File : date_time_fun4.php
<?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'));
?>
time() function , current UNIX timestamp return करता है जिसे हम strtotime() function() का use करके readable form में change कर सकते हैं।
File : date_time_fun5.php
<?php
$time_stamp = time();
echo "In Timestamp Format : $time_stamp";
echo "After change : ".date('h:i:s a', strtotime($time_stamp));
?>
date_default_timezone_get() function , current default timezone return करता है।
File : date_time_fun6.php
<?php
echo date_default_timezone_get();
?>
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook