PDA

View Full Version : system date



hongyi
09-13-2002, 08:21 AM
how to extract system date?

codes would be helpful.. thanks..

fivesidecube
09-13-2002, 08:50 AM
hongyi,
I think that following code give an example of the whole time structure:
$thetime = time;
@thelocaltime = localtime $thetime;

print "Year " . ($thelocaltime[5]+1900) . "\n";
print "Month " . ($thelocaltime[4]+1) . "\n";
print "Day $thelocaltime[3]\n";
print "Hour $thelocaltime[2]\n";
print "Mins $thelocaltime[1]\n";
print "Seconds $thelocaltime[0]\n";
print "Day of the week $thelocaltime[6]\n";
print "Day of the year $thelocaltime[7]\n";
print "Daylight savings " . ( $thelocaltime[8] ? "in force" : not in force) . "\n";

technophobia
09-13-2002, 08:55 PM
#in sudo-code so you do some work if you dont know this allready

somethings do suck about it. Like you have to add an if statement that checks if the $min is lower than 10, and if it is, you then have a value of '0' <--zero in the space before the actual minuite. This works if you leave the variable in front blank meaning as nothing.

another problem might be with hours. The time thing counts in military time or whatever it is called. To fix this you have to make another if statement and say.

if $hour>12 then $hour=$hour-12

now if you also want to place the AM or PM then you would say.

if $hour>12 then $hour=$hour-12, $am_or_pm='PM'
else $am_or_pm='AM'


i hope that made sence or that you coulde use this OR it actually works. this is more for if you want to format what the computer gives you.

-MARK