Check whether the string is a unix timestamp

后端 未结 12 1830
挽巷
挽巷 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:56

    This doesn't account for negative times(before 1970), nor does it account for extended ranges(you can use 64 bit integers so that a timestamp can represent a value far after 2038)

    $valid = ctype_digit($str) && $str <= 2147483647;
    

提交回复
热议问题