Date and Time
The packages\base\date class builds upon PHP's built-in language functions. Using these functions, additional custom helper functions have been created. For convenience, the methods of this class are written as static.
The advantage of using the date function becomes apparent when the site is designed to be multilingual and the calendar type differs between those languages. After switching the language, you can load the calendar type appropriate for that language using the setCanlenderName function, so that all the dates used throughout the website are updated consistently in one place.
Specifying the Default Calendar
For more information, refer to the Options page.
By adding an option named packages.base.date in the settings, the framework automatically loads the default calendar. The value of this option can be one of the following.
{"calendar": "jdate"}
// or
{"calendar": "gregorian"}
Time as a Timestamp
Using the time function, you can obtain the time as a timestamp.
date::time();
Converting a Timestamp to a Date
Using the format function, you can display a timestamp as a date. This function takes the calendar display format in its first parameter and the time in its second parameter. If no value is specified for the second parameter, it automatically converts the current time.
date::format(type, time);
The formatting notation of this function is exactly the same as the input parameters of PHP's date function, which you can read about on the following page.
http://ir2.php.net/date
Converting a Date to a Timestamp
Using the strtotime function, you can convert a date into a timestamp.
This function is most commonly used when a date is received from a form. To optimize the database, convert the date into a timestamp and store it in the database.
Example
// jalali calendar
echo date::time(); // 1493202918
echo date::format("Y F d"); // 1397 اردیبهشت 01
echo date::format("Y/F/d"); // 1397/اردیبهشت/01
echo date::format("Y/m/d"); // 1397/02/01
echo date::format("Y-m-d"); // 1397-02-01
echo date::format("Y-m-d", 1490610918); // 1397-01-07
echo date::strtotime("1396/04/18 22:17:37"); // 1499622457
// gregorian calendar
echo date::time(); // 1493202918
echo date::format("Y F d"); // 2018 April 21
echo date::format("Y/F/d"); // 2018/April/21
echo date::format("Y/m/d"); // 2018/04/21
echo date::format("Y-m-d"); // 2018-04-21
echo date::format("Y-m-d", 1490610918); // 2017-03-27
echo date::strtotime("2017/07/09 22:17:37"); // 1499622457