0

i'm trying to get the time in milliseconds from a string that could be with or without hours and without leading zeros, my actual attempts have been useless but here i'll show what i tried to do:

$duration_not_raw2 = date_create("00:00:00")->getTimestamp();        
$duration_not_raw = (date_create("1:59")->getTimestamp()) - $duration_not_raw2;

Please keep in mind that 1:59 could also become like 1:05:59 for 1 hour, 5 mins and 59 secs All i want would be to obtain like 95400 from 1:59 that would be the actual milliseconds for it

aynber
  • 20,647
  • 8
  • 49
  • 57
Beyoming
  • 11
  • 2
  • Convert the datetime into a unix timestamp or a time into seconds and multiply it by 1000, but keep in mind the integer overflow if you're on a 32 bit machine. – Honk der Hase May 25 '22 at 13:42
  • @HonkderHase I'm actually getting the timestamp but doesn't seems to give the correct values – Beyoming May 25 '22 at 13:48
  • @Gardener Online converters shows me 95400 for 1,59 minutes, i don't know, i might be wrong? – Beyoming May 25 '22 at 13:48
  • "1:59" is parsed as hours and minutes. Prepend "00:", so it's parsed as minutes and seconds. – gre_gor May 25 '22 at 13:54
  • Even then it's incorrect... 1hr 59min = 3600s + 3540s = 7140s – Honk der Hase May 25 '22 at 13:57
  • @gre_gor Well the thing i need it for is an API and that's video duration, the only thing i could think is to check for text length and eventually add 00: at that point... Because the video could be longer and taking hours – Beyoming May 25 '22 at 13:58
  • @HonkderHase Sadly i have huge issues with math, that's why i came here wondering for a solution, i'm willing to try it myself with some concepts – Beyoming May 25 '22 at 13:59
  • @HonkderHase OP seems to have converted 1 **comma** 59 minutes into milliseconds, not 1 minute and 59 seconds. – gre_gor May 25 '22 at 14:03
  • @gre_gor In that case i'm just wrong because of my math issues, what i want is to get 1 minute and 59 seconds into milliseconds. I was thinking 1,59 was gonna give me already that but yeah i was wrong – Beyoming May 25 '22 at 14:06
  • oooh 1.59 minutes, understood. Thanks for rectifying :) – Honk der Hase May 25 '22 at 14:23
  • @gre_gor Yes, it solved my issue, thank you so much!! I just did that * 1000 to obtain ms. I wish i was able to mark your reply as solved but i cannot do it with replies – Beyoming May 25 '22 at 15:03
  • Just accept the duplicate. – gre_gor May 25 '22 at 15:09

0 Answers0