I am getting the time from internet using the code
public static DateTime GetNistTime()
{
var myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
var response = myHttpWebRequest.GetResponseAsync();
string todaysDates = response.Result.Headers["date"];
return DateTime.ParseExact(todaysDates,
"ddd, dd MMM yyyy HH:mm:ss 'GMT'",
CultureInfo.InvariantCulture.DateTimeFormat,
DateTimeStyles.AssumeUniversal);
}
I got this code from here (made little changes to run on xamarin).
I am getting the time nicely but what I need is, I want to set the StartTimer to run the clock for every second by taking the above time as input.
I have tried the below code but the clock is not moving.
DateTime dt = GetNistTime();
Label timeNow = new Label();
Device.StartTimer(TimeSpan.FromSeconds(1), () => {
timeNow.Text = dt.ToUniversalTime().ToString("T");
return true; });
Any help would be appreciated .. Thanks in advance..