Hey everyone!
I've been trying to set up a more fool proof time trial thing for my windows application rather than checking the users computer for the time (that can easily be altered). I'm not that experienced with more advanced coding, and I just can't find any code that can do anything close to what I'm looking for either...
I came up with the idea of having a simple little self-updating clock on a website. The website prints just "06/11/2010" on it, but I simply can't pick it up... Everything I've tried only returns the actual html for the clock. It would seem like a simple task to just read what's printed on the page, but apparently it's not...
Is there any way to read what's actually printed on the website? Or somehow read the code "<iframe src="http://free.timeanddate.com/clock/i23768zn/n239/tlse/tt1/tw0/tm3/td2" frameborder="0" width="262" height="22"></iframe>" and get that into a DateTime?
The web clock page: http://kyuubibasher.webs.com/clock.html
Another path I looked into was connecting to a time server of some sort and get the current date that way, but I've never done such things before and I just can't find any decent code to start with...
So far the best I've managed had work is simply reading a .txt file that I've manually inputted the "todays date", but that's just not effective or what I want...
DateTime end = new DateTime(2010, 06, 12);
TimeSpan warning = new TimeSpan();
DateTime now = new DateTime();
DateTime blank = new DateTime();
string result = null;
string url = "http://kyuubibasher.webs.com/time.txt";
//part that needs to be changed somehow
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader tr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
result = tr.ReadLine();
tr.Close();
myResponse.Close();
//end part
try
{
now = Convert.ToDateTime(result);
}
catch
{
MessageBox.Show("Error reading from web, shutting down.", "Error!");
Application.Exit();
}
warning = end.Subtract(now);
time_trial_text.ForeColor = Color.FromArgb(225, 35, 35);
time_trial_text.Text = "Time trial expires in " + warning.Days + " days";
if (warning.Days <= 3)
{
time_trial_text.ForeColor = Color.FromArgb(225, 35, 35);
}
if (now > end || end == blank)
{
time_trial_text.Text = "Time trial has expired!";
MessageBox.Show("Time trial has expired!", "Warning!");
Application.Exit();
}
Or is there any other way of having the website print the time into something more readable or something? Maybe just a different clock?
Thanks in advance!