将EST日期时间转换为用户的时区和格式 [英] Converting EST datetime to user's timezone and format

查看:77
本文介绍了将EST日期时间转换为用户的时区和格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我的C#应用​​程序正由位于不同时区的用户使用..美国,英国,新加坡,澳大利亚等。


我需要能够转换这些输入日期并将其显示给用户wrt that timezone和dateformat ...

,例如,如果用户从LN访问应用程序,他们应该是日期以dd / mm / yyyy格式...所以应该向他们显示的日期(即3/5/2018 6:48:11 AM)是:

5/3/2018 11: 48:11 AM

依此类推。


这是我的尝试。但我不认为它将日期转换为英国格式...




string convertedDateAsString = null;

string dateTimeFormat =" MM / dd / yyyy hh:mm:ss tt,MM / dd / yyyy h:mm:ss tt,M / d / yyyy hh:mm:ss tt,M / d / yyyy h:mm:ss tt,M / dd / yyyy hh:mm:ss tt,M / dd / yyyy h:mm:ss tt,MM / d / yyyy hh:mm:ss tt,MM / d / yyyy h:mm:ss tt,MM / dd / yyyy" ;; $
                


string [] formats = dateTimeFormatList.Split(new [] {','})。选择(d => d.Trim())。ToArray();

DateTime tempParsedDate = DateTime.MinValue;


if(DateTime.TryParseExact(convertedDateAsString,formats,CultureInfo.CurrentCulture,

                    DateTimeStyles.None,out tempParsedDate))

                {

                    &NBSP ; convertedDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(tempParsedDate,"Eastern Standard Time",TimeZoneInfo.Local.Id);


       convertedDateAsString = convertedDateTime.ToString();


                }


谢谢。

解决方案

如果你了解他们的文化

 Application.CurrentCulture = New CultureInfo(" fr-BE")


如果使用SQL-Server,请考虑使用
DateTimeOffSet
数据类型。


Hello,

My C# application is being used by users who are present in different timezone..US, UK, Singapore, Australia etc.

I need to able to convert these input dates and show them to users wrt that timezone and dateformat...
for e.g.if the user is accessing app from LN,they should the date in dd/mm/yyyy format ...so the date(i.e. 3/5/2018 6:48:11 AM) that should be shown to them is:
5/3/2018 11:48:11 AM
And so on and so forth.

Here's my attempt.But I dont think it is converting date to UK format...


string convertedDateAsString = null;
string dateTimeFormat = "MM/dd/yyyy hh:mm:ss tt, MM/dd/yyyy h:mm:ss tt, M/d/yyyy hh:mm:ss tt, M/d/yyyy h:mm:ss tt, M/dd/yyyy hh:mm:ss tt, M/dd/yyyy h:mm:ss tt, MM/d/yyyy hh:mm:ss tt, MM/d/yyyy h:mm:ss tt, MM/dd/yyyy";
               
string[] formats = dateTimeFormatList.Split(new[] { ',' }).Select (d => d.Trim()).ToArray();
DateTime tempParsedDate = DateTime.MinValue;

if (DateTime.TryParseExact(convertedDateAsString, formats, CultureInfo.CurrentCulture,
                    DateTimeStyles.None, out tempParsedDate))
                {
                      convertedDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(tempParsedDate, "Eastern Standard Time", TimeZoneInfo.Local.Id);

       convertedDateAsString = convertedDateTime.ToString();

                }

Thanks.

解决方案

If you know their culture

Application.CurrentCulture = New CultureInfo("fr-BE")

If working with SQL-Server consider storing date/time with DateTimeOffSet data type.


这篇关于将EST日期时间转换为用户的时区和格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆