简体   繁体   中英

How to change the time in .php

I want to convert the time when i echo from database to .php page. When i upload a csv to database the table row with duration looks like this:

TABLE ROW:

|Duration|          

500     >   5:00
234     >   2:34
1100    >   11:00
520     >   5:20
1300    >   13:00
10000   >   1:00:00

So what i want is to show it like this > 5:00.

If i change the TABLE ROW Duration in to TIME than i get this 00:05:00.

So what do i need to change it like above explained ? Hopefully I explained it well

Thanks in advance.

<?php
foreach (array(500, 234, 1100, 520, 1300, 10000) as $number) {
    echo $number, "\t";
    $number = str_pad($number, 6, 0, STR_PAD_LEFT);
    echo ltrim($number{0}.$number{1}.':'.$number{2}.$number{3}.':'.$number{4}.$number{5}, ":0"), "\n";
}

http://codepad.org/FrjWtgqx

Function wordwrap() could be useful:

foreach (['500', '234', '1100', '520', '1300', '10000'] as $number) {
    $time = strrev($number);
    $time = wordwrap($time, 2, ':', true);
    $time = strrev($time);
    echo "$number was transformed to $time\n";
}

demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM