Formatting a number with leading zeros in PHP [duplicate]
Use sprintf : sprintf(‘%08d’, 1234567); Alternatively you can also use str_pad: str_pad($value, 8, ‘0’, STR_PAD_LEFT);
Use sprintf : sprintf(‘%08d’, 1234567); Alternatively you can also use str_pad: str_pad($value, 8, ‘0’, STR_PAD_LEFT);
Format timedelta to string
You need to double the {{ and }}: >>> x = ” {{ Hello }} {0} ” >>> print(x.format(42)) ‘ { Hello } 42 ‘ Here’s the relevant part of the Python documentation for format string syntax: Format strings contain “replacement fields” surrounded by curly braces {}. Anything that is not contained in braces is … Read more
The second parameter to date() needs to be a proper timestamp (seconds since January 1, 1970). You are passing a string, which date() can’t recognize. You can use strtotime() to convert a date string into a timestamp. However, even strtotime() doesn’t recognize the y-m-d-h-i-s format. PHP 5.3 and up Use DateTime::createFromFormat. It allows you to … Read more
try echo $time = date(“g:i A”, strtotime(“10:20:00”)); //output : 10:20 AM