Trying to use PHP DateTime Class with Yii2 receiving class not found errors

前端 未结 2 955
野的像风
野的像风 2020-12-29 05:03

Hello I am trying to create my own custom helper class to use with Yii2. It is going to handle times so I\'ll be working with PHP\'s DateTime class. I have



        
相关标签:
2条回答
  • 2020-12-29 05:21

    Add use for DateTime:

    use Yii;
    use DateTime;
    

    See use "global-namespace";

    0 讨论(0)
  • 2020-12-29 05:31

    Put a backslash in from of the class name to indicate it is in the global namespace:

    $time = new \DateTime('now', new \DateTimeZone('UTC'));
    
    0 讨论(0)
提交回复
热议问题