datetime - Exact styling of a difference in time (php) -


Two times (format: H: i: s ), I found another question on this site.

I tried it this way:

  $ start_date = new date time ('04: 10: 58 '); $ Since_start = $ start_date- & gt; Vary (new date time ('10: 25: 00 ')); Echo $ from_start-> H. ':'; Echo $ from_start-> I. ':'; Echo $ from_start-> S;  

But that output:

6: 14: 2

I think it does not look good. I want to see it: 06:14:02

I also want to use the current time instead of a given time, but what does not work with the above code I noticed

$ start_date = date ("h: i: s"); $ Since_start = $ start_date- & gt; Vary (new date time ('10: 25: 00 ')); Echo $ from_start-> H. ':'; Echo $ from_start-> I. ':'; Echo $ from_start-> S;

This output:

Fatal Error: Call the diff () member function on a non-object

I have twice: one time current time: date ("H: I: s") , second is a $ time0 in which for example 11 : 24: 00 (from a database).

internal date inward is formatted, and you should use the function :

  $ start_date = new date time ('04: 10: 58 '); $ Since_start = $ start_date- & gt; Vary (new date time ('10: 25: 00 ')); $ Resonance-$ d-> format ('% H:% I:% S'); For the second example, you are using a PHP string (since  date ()  returns a string, not an object) and trying to treat it in this way.  DateTime  object that causes you to get an error, you should instead start an empty  datetime  object which will be the default for  : 

  $ start_date = new dateTime (); // or datetime ('now') from $ $ - $ start_date- & gt; Diff (new date time ('10: 25: 00 ')); $ Resonance-$ d-> format ('% H:% I:% S');  

If you are starting the $ start_date value from a database, then assume that $ time0 You can send DateTime , which will whistle on converting it to the appropriate dateTime object:

  $ start_date = new date time ( $ Time0)); $ Since_start = $ start_date- & gt; Vary (new date time ('10: 25: 00 ')); $ Resonance-$ d-> format ('% H:% I:% S');  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -