5

Change the time of the server to the local time sent by Facebook

 2 years ago
source link: https://www.codesd.com/item/change-the-time-of-the-server-to-the-local-time-sent-by-facebook.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Change the time of the server to the local time sent by Facebook

advertisements

I am using Facebook C# SDK to get some data from my Facebook page.

When I get objects of data, at that time I get one field:

created_time : 2014-05-23T11:55:00+0000

As it is not same as my current time how do I convert it to my current time or to standard UTC time?


For me the code:

DateTime.Parse("2014-05-23T11:55:00+0000").ToString()

returns

2014-05-23 12:55:00

Because 'DateTime.Parse()` understands the timezone in this string, and by default produces a local time. My timezone being Irish Summer Time, one hour ahead of UTC, that means 2014-05-23T12:55:00 for me, for you it'll be a different time depending on your timezone.

For the converse, to get the time parsed in UTC (more useful for behind-the-scenes web stuff or storage, rather than user interface), use DateTime.Parse("2014-05-23T11:55:00+0000").ToUniversalTime()

If you need to deal with timezones other than local to the machine the code is running on, or UTC, then you will need to use DateTimeOffset, with the exception that DateTimeParse will handle other timezones in the string, but from that point on only has the concepts of "local time", "universal time" and "unknown timezone".


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK