Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

DateTime: Simple date operations in javascript

/*
### begin_: file metadata
    ### <region-file_info>
    ### main:
    ###   - name : cfDateTime.js
    ###     desc : |
    ###         Simple date operations in jscript.
    ###         This file is for use with windows scripting host.
    ###     date : created="Thu 2005-12-01 11:57:38"
    ###     last : lastmod="Thu 2005-12-01 12:18:57"
    ###     lang : jscript
    ###     tags : jscript javascript date time now month hour year cfDateTime
    ### </region-file_info>
    */

/// begin_: declare and init variables
    var today       = new Date();
    var strYear     = today.getFullYear();
    var iMonth      = today.getMonth() + 1; // +1, we do NOT want zero-based month index
    var iQuarter    = Math.ceil((iMonth / 12) * 4);
    var iDay        = today.getDate();
    var strDateOut  = "";

/// begin_: leading zeropad single-digit numbers
    iMonth = (iMonth < 10)? "0" + iMonth : iMonth;
    iDay = (iDay < 10)? "0" + iDay : iDay;

/// begin_: display output
    strDateOut = strYear+"-"+ iMonth +"-"+iDay + " ";
    WScript.Echo (strDateOut);

DateTime: generic date and time script in perl

### begin_: file metadata
    ### <region-file_info>
    ### main:
    ###   - name : DateTime.pl
    ###     desc : DateTime: generic date and time script in perl
    ###     date : created="Thu 2005-12-01 10:04:52"
    ###     last : lastmod="Thu 2005-12-01 10:04:59"
    ### </region-file_info>

### begin_: initialize perl (optional)
    use strict;
    use warnings;

### begin_: initialize DateTime values
    my %dttime = ();
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

### begin_: initialize DateTime number formats
    $dttime{year }  = sprintf "%04d",($year + 1900);  ## four digits to specify the year
    $dttime{mon  }  = sprintf "%02d",($mon + 1);      ## zeropad months
    $dttime{mday }  = sprintf "%02d",$mday;           ## zeropad day of the month
    $dttime{wday }  = sprintf "%02d",$wday + 1;       ## zeropad day of week; sunday = 1;
    $dttime{yday }  = sprintf "%02d",$yday;           ## zeropad nth day of the year
    $dttime{hour }  = sprintf "%02d",$hour;           ## zeropad hour
    $dttime{min  }  = sprintf "%02d",$min;            ## zeropad minutes
    $dttime{sec  }  = sprintf "%02d",$sec;            ## zeropad seconds
    $dttime{isdst}  = $isdst;

### begin_: xnpDate print iso8601 version date
    print "$dttime{year}-$dttime{mon}-$dttime{mday}\n";

### begin_: xnpNow show system time
    print "$dttime{year}-$dttime{mon}-$dttime{mday} $dttime{hour}:$dttime{min}:$dttime{sec} \n";



« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS