UnixTime

WebHome | UnixGeekTools | Geekfarm | About This Site

Pointers

dates

date


    # display current date in unix time
    date '+%s'

    # display date in format yyyymmdd-hh:mm:ss
    date '+%Y%m%d-%H%M%S'

    # calculate unix time at 8:30 today
    date '+%s-(%M*60+%S+%H*3600) + 3600*20+30*60' | bc

    # past unix times using gnu date
    date -d "1 day ago"
    date -d "yesterday"
    date -d '-1 day'
    date -d "Oct 10 1984 2 day ago"
    date -d "2006-10-26 18:35:00 2 day ago 3 hours ago"

    # converting unix date to human readable date
    perl -e'print scalar localtime( 1131200557 )'

    # touch a file with the time one hour ago - freebsd date
    touch -t $(date -v '-1H' '+%Y%m%d%H%M') ~/testme

Countdown


#!/usr/bin/perl -w
# countdown to U1e9
use strict;

my $now=time();
my $target='1000000000';
my
($sec,$min,$hrs,$dom,$mon,$year,$wday,$yday,$isdst)=localtime($target
- $now);
my $now_string=localtime(time());
my $target_string=localtime($target);
my $message=qq{today is $now_string\n$mon months $dom days $hrs hours $min minutes $sec seconds left till U1e9 ($target_string)\n}; print $message;




Updated Sun Jul 23, 2006 12:14 PM