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

About this user

drefty

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

DateTime: Simple date operations in javascript

   1  
   2  /*
   3  ### begin_: file metadata
   4      ### <region-file_info>
   5      ### main:
   6      ###   - name : cfDateTime.js
   7      ###     desc : |
   8      ###         Simple date operations in jscript.
   9      ###         This file is for use with windows scripting host.
  10      ###     date : created="Thu 2005-12-01 11:57:38"
  11      ###     last : lastmod="Thu 2005-12-01 12:18:57"
  12      ###     lang : jscript
  13      ###     tags : jscript javascript date time now month hour year cfDateTime
  14      ### </region-file_info>
  15      */
  16  
  17  /// begin_: declare and init variables
  18      var today       = new Date();
  19      var strYear     = today.getFullYear();
  20      var iMonth      = today.getMonth() + 1; // +1, we do NOT want zero-based month index
  21      var iQuarter    = Math.ceil((iMonth / 12) * 4);
  22      var iDay        = today.getDate();
  23      var strDateOut  = "";
  24  
  25  /// begin_: leading zeropad single-digit numbers
  26      iMonth = (iMonth < 10)? "0" + iMonth : iMonth;
  27      iDay = (iDay < 10)? "0" + iDay : iDay;
  28  
  29  /// begin_: display output
  30      strDateOut = strYear+"-"+ iMonth +"-"+iDay + " ";
  31      WScript.Echo (strDateOut);
  32  

DateTime: generic date and time script in perl

   1  
   2  ### begin_: file metadata
   3      ### <region-file_info>
   4      ### main:
   5      ###   - name : DateTime.pl
   6      ###     desc : DateTime: generic date and time script in perl
   7      ###     date : created="Thu 2005-12-01 10:04:52"
   8      ###     last : lastmod="Thu 2005-12-01 10:04:59"
   9      ### </region-file_info>
  10  
  11  ### begin_: initialize perl (optional)
  12      use strict;
  13      use warnings;
  14  
  15  ### begin_: initialize DateTime values
  16      my %dttime = ();
  17      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  18  
  19  ### begin_: initialize DateTime number formats
  20      $dttime{year }  = sprintf "%04d",($year + 1900);  ## four digits to specify the year
  21      $dttime{mon  }  = sprintf "%02d",($mon + 1);      ## zeropad months
  22      $dttime{mday }  = sprintf "%02d",$mday;           ## zeropad day of the month
  23      $dttime{wday }  = sprintf "%02d",$wday + 1;       ## zeropad day of week; sunday = 1;
  24      $dttime{yday }  = sprintf "%02d",$yday;           ## zeropad nth day of the year
  25      $dttime{hour }  = sprintf "%02d",$hour;           ## zeropad hour
  26      $dttime{min  }  = sprintf "%02d",$min;            ## zeropad minutes
  27      $dttime{sec  }  = sprintf "%02d",$sec;            ## zeropad seconds
  28      $dttime{isdst}  = $isdst;
  29  
  30  ### begin_: xnpDate print iso8601 version date
  31      print "$dttime{year}-$dttime{mon}-$dttime{mday}\n";
  32  
  33  ### begin_: xnpNow show system time
  34      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