How does the strtotime algorithm work (PHP Date function)?

  • I want to know how strtotime (php Date function) works?
  • how parse string Like "September 15, 2012" on timeStamp
  • Is there a better algorithm?

my goal changes this function for the Persian language

+3
source share
4 answers

You can view the PHP source code ( https://github.com/php/php-src ) and the search function to see its implementation.

UPDATE

Here is the algorithm of the strtotime () function https://github.com/php/php-src/blob/master/ext/date/php_date.c#L1324

Hi!.

+7
source

strtotime , : "15 (SOMETHING_PERSIAN) 2012" ( RegExp switch, ) "15 (SOMETHING_ENGLISH) 2012", strtotime

+3

I want to know how strtotime (php Date function) work?

Go here: https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.c

Find timelib_strtotime.

+3
source

forget about it using the php intl extension. will be part of the php core in the future.

<?php
    // format
    $format = datefmt_create('fa_IR@calendar=persian', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL, 'yyyy/MM/dd HH:mm');

    // time in locale as you wish
    var_dump(datefmt_format($format, time())); // '۱۳۹۱/۰۲/۰۴ ۱۹:۱۵'

ICU project support if you want to support i18n Persian for all languages.

php intl extension

icu-project.org

+2
source

All Articles