Check whether the string is a unix timestamp

后端 未结 12 1860
挽巷
挽巷 2020-11-27 16:43

I have a string and I need to find out whether it is a unix timestamp or not, how can I do that effectively?

I found this thread via Google, but it doesn\'t come up

12条回答
  •  鱼传尺愫
    2020-11-27 16:50

    As a unix timestamp is a integer, use is_int(). However as is_int() doesn't work on strings, we check if it is numeric and its intergal form is the same as its orignal form. Example:

    ( is_numeric($stamp) && (int)$stamp == $stamp )
    

提交回复
热议问题