Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
The code is:
a) vastly documented, for your ease of understanding.
b) thoroughly tested in Solaris 5.7, should run on any unix m/c
How to Info:
~~~~~~~~~~~~
How to run the scripts:
There are two attachments:
RunScript.sh
&
DateToTimestamp.pl
KEEP BOTH OF THEM IN THE SAME DIRECTORY
The first attachment "RunScript.sh" is a shell script.
It executes the "date" command
(which has your date format)
and
passes its output to DateToTimestamp.pl.
(which generates the Unix timestamp and prints it)
change its mode to executable
(by the command):
$ chmod 755 RunScript.sh
Then just run this script
(by the command):
$ RunScript.sh
And you get what you want.
REFERENCES
~~~~~~~~~~
1. Manuals
$ man date (for the manual on unix date format)
$ man mktime (for the manual on mktime method I used in .pl)
2. The POSIX library.
##############################################
DateToTimestamp.pl
#!/usr/local/bin/perl
#
# author: nabarun of [URL unfurl="true"]www.arzoo.com[/URL]
#
use POSIX;
my (
$wday,
$year,
$month,
$date,
$time,
$zone,
@wdays,
@months,
);
#
# Days in a week, as appears in the output of unix shell command "date"
#
@wdays = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
#
# Months in a year, as appears in the output of unix shell command "date"
#
@months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
#
# the date commands output is passed as the input here (by the RunScript.sh)
#
$inputDate = <STDIN>;
#
# storing the different words in the output
#
@words = split (/\s+/, $inputDate);
$wday = $words[0];
$month = $words[1];
$date = $words[2];
$time = $words[3];
$zone = $words[4];
$year = $words[5];
print "\ndate commands output:\n"
. "~~~~~~~~~~~~~~~~~~~~~\n\t\t$inputDate\n";
for($i = 0; $i <= $#wdays; $i++) {
if ("$wday" eq "$wdays[$i]") {
$wday = $i;
# print "$wday = $wdays[$i]\n";
last;
}
}
for($i = 0; $i <= $#months; $i++) {
if ("$month" eq "$months[$i]") {
$month = $i;
# print "$month = $months[$i]\n";
last;
}
}
@time_components = split (/\:/, $time);
$hour = $time_components[0];
$min = $time_components[1];
$sec = $time_components[2];
$year = $year - 1900;
print "arguments to the mktime() method:\n"
. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n";
print "sec = $sec, min = $min, hour = $hour,\ndate = $date, month = $month, "
. "year (this yr. - 1900) = $year, day = $wday \n\n";
$timestamp = mktime($sec, $min, $hour, $date, $month, $year, $wday, 0, -1);
print "********************************\n";
print "CALCULATED TIMESTAMP = ";
print "$timestamp \n";
print "********************************\n";
print "PRESENT TIMESTAMP = ";
print (time());
print "\n";
print "********************************\n\n";
##################################
RunScript.sh
#!/bin/sh
clear;
#
# run the unix command date and pass its input to the output of
# the perl script DateToTimeStamp.pl.
#
date | perl DateToTimestamp.pl;