Friday, January 23, 2015

Nuget Package : Google Time Zone Api for .NET

I have created Google Time Zone Api for .NET as a Nuget package so it can be easily integrated to who ever is in need in converting time between on geographic locations.

To install Google Time Zone Api for .NET, you can either run the following command in the Package Manager Console.

PM> Install-Package Google.TimeZoneApi

Or you can directly install it through Manage Nuget Packages window.
image
Nuget Packages Window
How you can use it as follows. You will need to have a Google TImeZone API Key which can be acquired for free to use this Google TimeZone Api for .NET.
using System;
using Google.TimeZoneApi;
 
namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            GoogleTimeZone googleTimeZone = new GoogleTimeZone("your api key");
 
            string timeString = "2015-01-01T08:00:00.000+05:30";
            DateTime dt = DateTime.Parse(timeString);
 
            string location = "Seattle, United States";
 
            GoogleTimeZoneResult googleTimeZoneResult = googleTimeZone.ConvertDateTime(dt, location);
            Console.WriteLine("DateTime on the server : " + dt);
            Console.WriteLine("Server time in particular to : " + location);
            Console.WriteLine("TimeZone Id : " + googleTimeZoneResult.TimeZoneId);
            Console.WriteLine("TimeZone Name : " + googleTimeZoneResult.TimeZoneName);
            Console.WriteLine("Converted DateTime : " + googleTimeZoneResult.DateTime);
        }
    }
}

image
Result
I have also added the source code for this Nuget package to GitHub making it public. Please feel free to contribute and to leave your valuable feedback.

Source on GitHub
     https://github.com/jaliyaudagedara/Google.TimeZoneApi

Happy Coding.

Regards,
Jaliya

No comments:

Post a Comment