Click here to Skip to main content
15,887,446 members
Articles / Programming Languages / C#
Tip/Trick

How to get server side date time without your own server

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
29 Mar 2012CPOL 17.5K   5   1
How to get server side date-time in your Windows Application for free.

Introduction

Sometimes we want to get server side date-time but we do not have our server to do it. This article teaches you how you can do this (I use Google.com's Header site).

Background

I use the System.Net Namespace to do it.

Using the code

C++
string URL = "http://www.google.com";    
System.Net.HttpWebRequest rq2 = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL);
System.Net.HttpWebResponse res2 = (System.Net.HttpWebResponse)rq2.GetResponse();
DateTime Date = DateTime.Parse(res2.Headers["Date"]); 

Now , you can get server side date and time in your DateTime variable.

Enjoy ;-)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer 1
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionvote 5 Pin
beqiraj2545-Apr-12 23:04
beqiraj2545-Apr-12 23:04 
thank you very much for the tip my friend

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.