php - how to modify time ago script to show time in form of DD-MM-YYYY -


I have a time ago script that changes almost a UNIX stamp as a code example: 1 Minutes

My script (PHP):

   

My question : How do I modify this script to show the Unix timestamp, which is 2 years old and dd-mm- Yyy format


Explanation for those who did not understand

A test code / script

  & lt; Php $ initial_time = "946681200"; // Unix timestamp is for 1 January 2001 $ period = array ("seconds", "minute", "hour", "day", "week", "month", "man"); $ Length = array ("60", "60", "24", "7", "4.35", "12", "10"); $ Span = time () - $ initial_time; $ Stress = "first"; ($ J = 0; $ span & gt; = $ length [$ j] & amp; amp; $ j & lt; counts ($ length) -1; $ j ++) {$ span / = $ length [$ J]; } $ Span = round ($ span); If ($ span! = 1) {$ periods [$ j] = "S"; } $ Time_elapse = $ span ''. $ Period [$ j]; ? & Gt;  

The above code will change the Unix time stamp "946681200" to be around one time i.e. 14yrs , but I want to show everyone

This code is two, two years of unix time stamp in DD-MM-YYYY format. Create a datetime object: which represents two years ago, which represents your initial time It then compares them (the date time object is comparable) if $ initial_date is more than two years ago, then it specifies that format in the format you requested $ Time_elapse otherwise your code runs normally.

  & lt ;? Php $ initial_time = "946681200"; // Unix timestamp is for December 31, 1999 $ two_years_ago = new date time ('- 2 years'); $ Initial_date = new date time ('@'. $ Initial_time); If ($ initial_date & lt; $ two_years_ago) {$ time_elapse = $ initial_date-> Format ('D-M-Y'); } And {$ period = array ("seconds", "minute", "hour", "day", "week", "month", "year"); $ Length = array ("60", "60", "24", "7", "4.35", "12", "10"); $ Span = time () - $ initial_time; $ Stress = "first"; ($ J = 0; $ span & gt; = $ length [$ j] & amp; amp; $ j & lt; counts ($ length) -1; $ j ++) {$ span / = $ length [$ J]; } $ Span = round ($ span); If ($ span! = 1) {$ periods [$ j] = "S"; } $ Time_elapse = $ span ''. $ Period [$ j]; }? & Gt;  


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -