Http://yangjunwei.com/a/930.html
php function Gmstrftime () converts seconds to days
A scenario needs to use the countdown seconds, such as Sina Weibo license validity period remaining: 7 days 16 hours 47 minutes 42 seconds ...
In PHP environment, PHP function Gmstrftime () can be converted to convert seconds to hours and minutes, first look at the example:
Define ("Bjtimestamp", Time ()); Server current time $expires_in= ' 1439577160 ';//expiry time $expires= $expires _in-bjtimestamp;function Time2second ($seconds) {$ seconds = (int) $seconds, if ($seconds <86400) {//if less than one day $format_time = Gmstrftime ('%h%m minute%s seconds ', $seconds);} else{$time = Explode ("', Gmstrftime ('%j%H%M%s ', $seconds));//array ([0] = [1] = [2] = [3] = = $format _time = ($time [0]-1). ' Day '. $time [1]. ' Time '. $time [2]. ' Points '. $time [3]. ' Seconds ';} return $format _time;} echo "Sina Weibo license validity period remaining:". Time2second ($expires). '
Note: the Gmstrftime () function returns the number of days in a year, so that it takes more than one year to use the following code.
For more detailed partitioning, the following examples are available:
function Time2second ($seconds) {$seconds = (int) $seconds, if ($seconds >3600) {if ($seconds >24*3600) {$days = (int) ( $seconds/86400); $days _num= $days. " Day "; $seconds = $seconds%86400;//} $hours = Intval ($seconds/3600); $minutes = $seconds%3600;//take the remaining seconds. = $days _num.$ Hours. " Hours ". Gmstrftime ('%m minutes%s seconds ', $minutes);} else{$time = gmstrftime ('%h hours%m minutes%s seconds ', $seconds);} return $time;} echo "Sina Weibo license validity period remaining:". Time2second ($expires). '
Finally, the use and parameters of the function gmstrftime ():
Grammar:
Gmstrftime (Format,timestamp)
Parameters and Description:
Format required parameter; Specifies the method that returns the result:%a-abbreviated weekday name abbreviation for the day of the week,%a-full weekday names represents the day of the week.%b-abbreviated Month Name Month abbreviation%b-full month name month full%c-preferred date and time representation preferred datetime representation%c-century number (the year divided By, Range xx to 99) represents the number of the century (the year divided by 100, ranging from 00 to%d-same)%d-day of the Month (31) One months contains the number of days (from 01 to) as%m/%d/%y time Format, same as%m/%d/%y notation%e-day of the month (1 to 31) one months, excluding 0 (from 1 to)%g-like%g, except without the century and%g, but the "century [Century] "%g-4-digit year corresponding to the ISO week number (see%V). The 4-digit year corresponding to the ISO week number (see%V)%h-same as%b is the same as%b%h-hour, using a 24-hour clock (23) hours, 24-hour clock (00 to 12-hour clock (up to 12) hours, use 12-hour clock (01 to 366)%j-day of the year (from 001 to 366)%m-month (12-01 )%m-minute min%n-newline character newline character%p-either am or PM according to the given time value corresponds to the value given in AM or Pm%r-time In a.m. and p.m. notation with AM or PM for a given time%r-time in hour notation with 24-hour notation time%s-second sec%t-tab character tab/tab%t-current time, equal to%h:%m:%s current times, same as "%h:%m:%s" combination%u-weekday as A number (1 to 7), Monday=1. Warning:in Sun Solaris Sunday=1 is a digital representation of the Day of the week (1 to 7), Monday=1. Reminder: In the Sun Sloaris system, Sunday=1%u-week number of the current year, starting with the first Sunday as the first day of the fi RST week the total number of weeks that are contained in today's year, with the first Sunday as the first day of the first week%v-the ISO 8601 Week numbers of the current years, where Week 1 is the FI RST week that have at least 4 days in the present year, and with Monday as the first day of the week under the ISO 8601 format contained in today's The total number of weeks (01 to week), 1 for the first week, and Monday as the first day of the week%w-week numbers of the current year, starting with the primary Monday as the " F The first week the total number of weeks contained in the current year, with the first day of the first week of Monday as%w-day of the week as a decimal, sunday=0 expressed as a number of days of the week, sunday[Sunday]=0%X-PR eferred date representation without the time to select the day to remove times [date]%x-preferred hours representation without the date selected to remove Date [Date] time [Time]%y-year without a century (range xx to 99) Displays only numbers that contain the year, and does not contain numbers that represent the century (00-99)%y-year including the century displays the year of the century number (i.e., four digits of the year, such as: 1999,2001, etc.)%Z or%z-time zone O R name or abbreviation is the time zone name, and the latter is the name of the time zone named percent-a literal% character output "%" string timestamp optional parameters. Specifies the format of the date or time. If you do not specify a timestamp [timestamp], the current GMT time is used by default.
Tip: the Gmstrftime () function is roughly the same as the strftime () function, and the only difference is the Greenwich Mean Time (Gmt:greenwich Mean time) returned by the Gmstrftime () function.
4 Reviews»
php function Gmstrftime () converts seconds to days