Web & Software Developer

Posts Tagged “time”

PHP mktime() Changes Your Time, Here’s the Fix

If you’re using PHP mktime() to make a timestamp for a specific moment in time that should not change, then be sure to first set the default timezone to UTC. Otherwise, the dynamic behavior of mktime() is to modify or change your time, based on the timezone settings on your server. This may be desirable … Read more →

PHP strftime() is Faster Than date() in PHP 7

After running several benchmark tests, I find that the PHP strftime() is faster than date(). I tested each one creating the same datetime string in this format: ‘YYYY-MM-DD HH:MM’. The test iterates 100000 times over each function. I repeated this test several times. Each time, I alternated which function ran first. Here are the benchmark … Read more →

Detect if WP Time Format is in 24-hr Format

This function lets you detect if the Time Format in WordPress settings is set to a 24-hour format. It returns true if the Time Format is in a 24-hour format, otherwise it returns false. (The Time Format is also known as the ‘time_format’ option, and you can get it like this: get_option( ‘time_format’ ).)

IANA/Olson Time Zone Offset Search Tool

This timezone search tool lets you look up a time zone from the IANA/Olson timezone database. This calculator is mainly for looking up a historical timezone offset (time difference from UTC/GMT). That is, a timezone offset for a city for a historical date and time. A historical date is any date in the past. This … Read more →

Convert Time From 24-hour Format to 12-hour Format

This is a PHP function to convert time from 24-hour format (HH:MM) into 12-hour format, with am or pm added. It takes two parameters: the hour the minute (with a leading zero for 0 through 9) It returns the time in 12-format like this: HH:MM am/pm

Get Local Time in PHP with localtime

This will get the local time from the visitor’s browser. Then it converts PHP’s localtime() function into a readable display format, with leading zeros before the single-digit minutes. It also converts time into 12-hour format and appends the meridian ( am/pm ) to it. Then it displays the final time, formatted nicely, like See below … Read more →