skip to Main Content

yii2 have a function that transform something like ‘1671380485’ to ‘December 21, 2022’.

Yii::$app->formatter->asDate('1671380485', 'medium');

Do yii2 have a function that will make Reverse effect? For example transform ‘2022-12-21’ to int(11)?

2

Answers


  1. I believe PHP’s strtotime() function is what you are looking for:

    <?php
    echo strtotime('2022-12-21'); // 1671606000
    ?>
    
    Login or Signup to reply.
  2. Yes, you can use the built-in formatter:

    Yii::$app->formatter->asTimestamp('2022-12-21'); 
    

    Read more here: https://www.yiiframework.com/doc/api/2.0/yii-i18n-formatter#asTimestamp()-detail

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search