Click to See Complete Forum and Search --> : Has anybody got the correct time????


Mr.Mike
09-12-2003, 11:07 PM
Hi folks,
Could some one please tell me what to change in this script below, to show time in the thank you/submitted results page. I would like it non milatary & est, not pacific time.
also to state that it's EST.

I know this part below is got something to do with it.
Just can't seem to fig. out which part changes it.

Please let me know
Regards,
Mike

+++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++

# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;

# Format the date. #
$date = "$days[$wday], $months[$mon] $mday, $year at $time";

simpson97
09-13-2003, 01:12 AM
Mike,
Study following script - it works.

#!/usr/bin/perl

$gmt_offset = 60 * 60 * 4;

$now = getTime($gmt_offset, "EST");

print "$now\n";

exit;

sub getTime {
my ($gmt_offset, $zone) = @_;
my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time - $gmt_offset);
my $time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;
$AmPm = "AM";
if($hour>12) { $hour -= 12; $AmPm = "PM"}
return "$days[$wday], $months[$mon] $mday, $year at $time $AmPm $zone";
}

exit(0);

The crux is to get gmtime - time zone offset.

my $sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time - $gmt_offset);

Bob

Mr.Mike
09-13-2003, 03:59 AM
Well, I got it to reconize am & pm.

Now it states the time 4 hours ahead of what it should.


Any more input as to were I'm going wrong bob?

:confused:

My ajustments below

Regards,
Mike


+++++++++++++++++++++++++++++++++++

sub get_date {

# Define arrays for the day of the week and month of the year. #
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');

# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #
($sec,$min,$hour,$mday,$mon,$year,$wday,$isdst) = gmtime(time + $est_offset);
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;
$AmPm = "AM";
if($hour>12) { $hour -= 12; $AmPm = "PM"}
# Format the date. #
$date = "$days[$wday], $months[$mon] $mday, $year $time $AmPm $zone est.";
}

simpson97
09-13-2003, 01:56 PM
Mike, try this.

sub get_date {

# Define arrays for the day of the week and month of the year. #
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June'
,'July',
'August','September','October','November','Decembe
r');

# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #

# Mike you have so subtract offset from gmtime - you were adding offset
($sec,$min,$hour,$mday,$mon,$year,$wday,$isdst) = gmtime(time - $est_offset);

$year += 1900;
$AmPm = "AM";
if($hour>12) { $hour -= 12; $AmPm = "PM"}

# also moved this line
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);

# Format the date. #
$date = "$days[$wday], $months[$mon] $mday, $year $time $AmPm $zone est.";
}

Bob

Mr.Mike
09-13-2003, 07:21 PM
I don't think this is working.
Followed the instructions to the letter.

I was fooled earlier this mornig with the AM /PM deal.

right now at this moment it is Sat. 13th 8:10 pm est and here is what the results were from the script:

Sunday, September 14, 2003 00:07:18 AM est.


:eek: :mad: :confused:


Mike

Charles
09-13-2003, 08:01 PM
It would seem to me that something odd is going on. Mike, what do you get when you run the following and how does it compare to the current time?

print scalar localtime;

simpson97
09-13-2003, 08:04 PM
Mike,
Use this line in script

($sec,$min,$hour,$mday,$mon,$year,$wday,$isdst) = gmtime(time - 18000);

instead of other line that contains $est_offset

Bob

Mr.Mike
09-13-2003, 10:15 PM
Bob,

Thank you for your patients and input; thats the winning ticket. I just had to dial in the time offset a little more to fit my zone. (completed script below)

and the am pm works too...

Charles not sure where your going with that command but we got this other one working and thats good for me.

:D :D :D
Thanks
Mike

++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
sub get_date {

# Define arrays for the day of the week and month of the year. #
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');

# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #
($sec,$min,$hour,$mday,$mon,$year,$wday,$isdst) = gmtime(time - 14500);

$year += 1900;
$AmPm = "AM";
if($hour>12) { $hour -= 12; $AmPm = "PM"}

$time = sprintf("%02d:%02d",$hour,$min);

# Format the date. #
$date = "$days[$wday], $months[$mon] $mday, $year $time $AmPm est.";

}

Charles
09-14-2003, 07:06 AM
Originally posted by Mr.Mike
Charles not sure where your going with that command but we got this other one working and thats good for me.I thought, perhaps, the time was set wrong on the computer running the interpreter. Be advised that your script will stop working correctly when daylight time ends. You would do better to use "localtime".

Mr.Mike
09-14-2003, 02:28 PM
Charles,
This is what I started with (below) and it kept giving me pacific miltary time.

Can you advise for this original question?
(Also please read first string of this thread)

Regards,
Mike


++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
sub get_date {

# Define arrays for the day of the week and month of the year. #
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');

# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;

# Format the date. #
$date = "$days[$wday], $months[$mon] $mday, $year at $time";

}

zachzach
09-15-2003, 03:52 PM
wow im not good at this thats good