Coutdown program

Discuss Programming
Post Reply
shuiend
scripter
scripter
Posts: 91
Joined: Mon Apr 28, 2003 8:05 pm

Coutdown program

Post by shuiend »

Ok i turn 18 in 404 days from now and i was wondering how i would go about making a program in linux to keep track of that date? I would like a nice gui which i could do in QT but i was wondering if there are any c++ functions to get like the system time or something. I would like to get it down to minutes and seconds to if possible.

ZiaTioN
administrator
administrator
Posts: 460
Joined: Tue Apr 08, 2003 3:28 pm
Contact:

Post by ZiaTioN »

You could capture the output of the "date" command in Linux. I wrote this small example in Perl but you can follow the logic.

Code: Select all

#!/usr/bin/perl -w

use strict;

my $date = `date`;
my $bday = "Jan 15 22:30:00";

my @array  = split(/ /, $date);
my $string = $array[1]." ".$array[2]." ".$array[3];

if ($string eq $bday) {
   print "It is your birthday!\n";
}else{
   print "Not yet!\n";
}
You just need to make sure you keep the format of $bday the same as this is a portion of the same format that the "date" command in Linux will return. As far as the reporting how long left until your birthday I am sure you can handle the math functions. The thing about getting your results down to the second is that you would have to run the script every second to be accurate which would chew up quiet a bit of system resources.

Post Reply