2013-02-27

ISO-8601

This. So much this.

In C:
#include <stdio.h> #include <time.h> #define SIZE 0x100 int main () { time_t t; char buffer[SIZE]; struct tm ltime; t = time (0); localtime_r (& t, & ltime); strftime (buffer, SIZE, "%Y-%m-%d", & ltime); printf ("%s\n", buffer); return 0; }
In Bourne-derived shell:
#!/bin/sh iso8601=`date +%Y-%m-%d` echo $iso8601
In Perl:
#!/usr/bin/perl use POSIX qw/strftime/; my $date = strftime "%Y-%m-%d", localtime; print "$date\n";
In Ruby:
#!/usr/bin/ruby iso8601 = Time.now.strftime("%Y-%m-%d") p iso8601
In PHP:
<?php $iso8601=date('Y-m-d'); print $iso8601."\n";
In Python:
#!/usr/bin/python from datetime import date iso8601=date.today().isoformat() print iso8601
Got it? Good.

blog comments powered by Disqus