简体   繁体   中英

Convert UNIX Epoch to Datetime depending on culture

I'm developing a method that will receive UNIX timestamp and culture:

public DateTime unixEpochToDateTime(long unixTimeStamp, string culture) {
    ...
}

Call example:

DateTime t = unixEpochToDateTime(1478181983, "es-ES");

I need convert this UTC time between many cultures, without using TimeZone.CurrentTimeZone because this method will be run in server and the server culture is allways the same.

For example, if two user request my method in EE.UU and in Great Britain, I get the same UTC?

I'm very confused.

I think that you can try nodatime . It has many usefull methods.

Problem solved...

If .NET does not provide a mechanism is because it is impossible to determine the time difference UTC based on culture.

Basically because a culture can have different time zones.

Culture "es-ES" for example, has 2 zones: GTM + 0 for Canary Islands and UTC + 1 for Iberian Peninsula.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM