时间转换问题 [英] Time Converting Problem

查看:80
本文介绍了时间转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在数据库中插入日期和时间。



插入正常,但是时间是插入服务器时间?



如何解决这个问题。







我有 04/09 / 2013,11:13:00 AM

当我插入它时 04/09 / 2013,1:13:00(我们)。



我想插入04/09 / 2013,11:13:00 AM。



  //  我这样传递时间 
CultureInfo CI = new CultureInfo( EN-US);
// puch.Time = 04/09 / 2013,11:13:00 AM
obj.Scanned_Time = Convert.ToDateTime(Puch.Time.ToString( T, CI));
// 数据库存储如此04/09 / 2013,1:13:00 AM(我们)
// 此处的日期,时间是两个不同的字段



这里的日期,时间是两个不同的字段



那怎么能解决?





提前致谢............

解决方案

如果你在服务器上使用云访问只需更改时间格式并将时间设置为所需格式,因为默认情况下它将占用服务器日期时间。或者





如果您在服务器上没有云访问权限,则可以在扣除120分钟后插入所需时间。


请查看以下链接。



在时区之间转换时间 [ ^ ]



TimeZoneInfo.ConvertTime方法 [ ^ ]


为什么要创建US类型的CultureInfo?我不知道这会不会改变你的时间,但这不是我会做的事情。



就个人而言,我会这样做:



 obj.Scanned_Time = Puch.Time; 



没有文化信息。


Hi all,

I m inserting date and time in database.

It's inserting fine, but time is inserting server time?

How can solve this.



I Have 04/09/2013, 11:13:00 AM
when I Inserting it's 04/09/2013 ,1:13:00 AM (us).

I want to Insert 04/09/2013 ,11:13:00 AM.

//Im passing time like this
CultureInfo CI = new CultureInfo("en-US");
//puch.Time=04/09/2013, 11:13:00 AM 
obj.Scanned_Time = Convert.ToDateTime(Puch.Time.ToString("T", CI));
//in database storing like this 04/09/2013, 1:13:00 AM (us)
//here the date,time is two different fields


here the date,time is two different fields

So how can solve?


Thanks in advance............

解决方案

If you have cloud Access on server just change the Time Format and set the time as your desired format because by default it will take Server Date Time. or


If you don't have cloud access on server, You can Insert it after deducting 120 mins for your desired time.


Please check below links.

Converting Times Between Time Zones[^]

TimeZoneInfo.ConvertTime Method [^]


Why are you creating a CultureInfo of type US? I have no idea if this will convert your time or not, but it is not something I would do.

Personally I would just do this:

obj.Scanned_Time = Puch.Time;


without the culture info.


这篇关于时间转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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