Getting RTC Time


To read current time from RTC, pid_ioctl function is used.

pid_ioctl($pid, "get ITEM");

Available RTC Information

ITEM Description Return Value Return Type
date date and time e.g. 20160720135607 string
wday day of week 0: Sun, 1: Mon, 2: Tue, 3: Wed,
4: Thu, 5: Fri, 6: Sat
integer

example of getting RTC information

<?php
$date = "";
$wday = 0;
$pid = pid_open("/mmap/rtc0");        // open RTC 0
$date = pid_ioctl($pid, "get date");  // get the date and time
$wday = pid_ioctl($pid, "get wday");  // get the day of week
pid_close($pid);
?>

※ Return value of RTC time has the same structure with a value for setting time.

"date()" Function

PHPoC provides an internal function for getting RTC information. You can get RTC information with various formats by using this function.

example of getting RTC information by "date()" function

<?php
$date1 = date("Y-m-d H:i:s");       
$date2 = date("D M j H:i:s Y"); 
echo "$date1\r\n";                // output e.g. 2016-07-20 13:56:07
echo "$date2\r\n";                // output e.g. Wed Jul 20 13:56:07 2016
?>

※ Refer to the PHPoC Internal Functions document for detailed information of date function.