Click here to Skip to main content
Click here to Skip to main content

How to get server side date time without your own server

, 29 Mar 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
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

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 Wink | ;-)

License

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

Share

About the Author

MB Seifollahi
Software Developer 1
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

Comments and Discussions

 
Questionvote 5 Pinmemberbeqiraj2545-Apr-12 23:04 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 29 Mar 2012
Article Copyright 2012 by MB Seifollahi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid