Home  >  Article  >  Backend Development  >  对于社保截止日接口的学习记要-对于php时间的操作(date_time和timestamp)

对于社保截止日接口的学习记要-对于php时间的操作(date_time和timestamp)

WBOY
WBOYOriginal
2016-06-13 12:19:39936browse

对于社保截止日接口的学习记录---对于php时间的操作(date_time和timestamp)

首先,是对于时间的操作,通过几个例子来说吧

<code class=" hljs mel"><span class="hljs-variable">$remind_time_now</span> = <span class="hljs-keyword">date</span>(<span class="hljs-string">'Y-m-d'</span>,<span class="hljs-variable">$end_time</span>).<span class="hljs-string">'09:00:00'</span>;</code>

这个是对时间戳进行转换,date函数有很多的转换方式,第一个参数就是表示你需要的格式,如果有时候,你需要只需要时间戳提供年月日,然后几点几分这些数据你自己定的话,可以用这种方式将时间戳转化为年月日的形式,然后拼接上时间的数据,要空格 然后 几点:几分:几秒。

<code class=" hljs perl"><span class="hljs-variable">$y</span> = <span class="hljs-keyword">substr</span>(<span class="hljs-variable">$remind_date</span>,<span class="hljs-number">0</span>,<span class="hljs-number">4</span>);<span class="hljs-variable">$m</span> = <span class="hljs-keyword">substr</span>(<span class="hljs-variable">$remind_date</span>,<span class="hljs-number">5</span>,<span class="hljs-number">2</span>);<span class="hljs-variable">$d</span> = <span class="hljs-keyword">substr</span>(<span class="hljs-variable">$remind_date</span>,<span class="hljs-number">8</span>,<span class="hljs-number">2</span>);</code>

如果你接收到到的时间数据为2015-02-05的话,可以通过substr这种字符串截断的方法来获取你想要的时间,可以获取年月日对应的数字

<code class=" hljs bash"><span class="hljs-variable">$end_time</span> = strtotime(<span class="hljs-variable">$data</span>[<span class="hljs-string">'end_time'</span>]);</code>

strtotime这个方法是将2015-11-11 09:22:22这种date time 的格式转化为时间戳的形式。

<code class=" hljs perl"><span class="hljs-variable">$remind_timestamp</span> = <span class="hljs-variable">$end_time</span>+<span class="hljs-number">4</span><span class="hljs-variable">*60</span><span class="hljs-variable">*60</span><span class="hljs-variable">*24</span>;</code>

这个方法就是给你给定的时间戳加上几天的时间,一天的时间戳长度为60*60*24。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn