I asked ChatGPT to format php datetime as “Fri 24 Mar 2023” and it “understood” what I meant and gave me the answer that I wanted! If that’s not intelligence I don’t know what is…
Tag Archives: format
KDE widget date/time format
Date/Time formats for the KDE clock widget.
Announcing numformat.php
So I was reading output from
/proc/spl/kstat/zfs/arcstats
and I couldn’t read it easily because the numbers weren’t formatted with thousands separators and I figured I could fix that…
I give you numformat.php. It automatically reformats any input that looks like a number…
There’s more info on the programming@progclub mailing list.
Linux/POSIX username conventions
PHP DateTimeZone->getOffset()
Today I had to use PHP’s DateTimeZone->getOffset() to get a timezone offset. It needed formatting which I did with:
function timezone_offset() { $offset = timezone()->getOffset( now() ); $hours = round( abs( $offset ) / 3600 ); $minutes = round( ( abs( $offset ) - $hours * 3600 ) / 60 ); $result = ( $offset < 0 ? '-' : '+' ) . ( $hours < 10 ? '0' : '' ) . $hours . ':' . ( $minutes < 10 ? '0' : '' ) . $minutes; return $result; }
Formatting timezones in PHP
All you need to know is on the date documentation…
Formatting a float as a percentage in PHP
To format a float value as a percentage in PHP:
$formatted = sprintf( '%.2f', $value * 100 );
Portable Executable 101 – a windows executable walkthrough
Saw this Portable Executable 101 – a windows executable walkthrough today. Pretty cool visualisation.
Unix command to format a number of bytes as a human readable value
It took me a while, but I finally figured out how to print a number from a bash script properly formatted with commas as thousand’s separators. For those like me who weren’t in the know, the magical incantation is:
printf "%'d" 123456
That will format 123456 as 123,456. Much easier to read when you’re dealing with large numbers such as the sizes of files in gigabytes.
So now if I could only find the Unix command that took a number of bytes and turned it into an approximate value with GB or MB suffixes.