将数据集转换为XML时如何在Xml中更改Dateformat [英] How to change Dateformat in Xml while converting dataset to XML

查看:287
本文介绍了将数据集转换为XML时如何在Xml中更改Dateformat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将xml(dataset)插入sql server时出现错误,无法将此xml日期格式(2011-02-04T00:00:00 + 05:30)转换为sqlxerver的dateformat.

我的编码:

I got error when insert xml(dataset) into sql server by that cannot convert this xml date format(2011-02-04T00:00:00+05:30) into dateformat of sqlxerver.

My coding:

Dataset dsTemp=new DataSet();
dsTemp.Tables.Add(MyDataTable);                                         


1 ...//以上DateField格式为2011年3月2日下午12:00:00


1...//Above DateField format is 03/02/2011 12:00:00PM

string xx= dsTemp.GetXml();


2 ....//以上DateField格式为(2011-02-04T00:00:00 + 05:30)

如何将2更改为1:
请指导我...

OP的更新:
我暂时得到了解决方案.在sql server中,我将前10个字母组成子字符串并存储.
这只是暂时的解决方案.所以请给任何一个技术解决方案.例如:如何更改DataSet.GetXml()


2....//Above DateField format is (2011-02-04T00:00:00+05:30)

How to change 2 to 1:
Please guide me...

UPDATE from OP:
I got solution temporarily. In sql server i substring first 10 letter and stored.
it is only temporarily solution . so plz any one give technical solution. for ex: how to change date format in DataSet.GetXml()

推荐答案

嗨Karthikvadugan,
中的日期格式
getXML()将日期格式更改为UTC.在插入sql服务器之前,可能需要阅读XML并转换日期格式.可以使用以下转换代码将UTC格式的字符串转换为任何其他DateTime格式.

字符串结果= Convert.ToDateTime("2011-02-04T00:00:00 + 05:30").ToString("MM/dd/yyyy h:mm:ss tt");

如果您指定未指定的数据列日期时间模式,则不会附加+5:30小时.

myDateColumn.DateTimeMode = System.Data.DataSetDateTime.Unspecified;

但是,如果来自不同时区的用户输入数据,则最好考虑UTC偏移.为此,需要以通用时间格式存储数据,然后在显示时将其转换为任何区域.可以减去+5:30的偏移量,因此可以获取子午线时间并进行存储.以后可能会转换为IST并显示.如果数据是从同一时区输入的,则只需忽略UTC偏移.
Hi Karthikvadugan,

The getXML() changes the date format to UTC. May need to read the XML and convert the date formats before insert into the sql server. Can use the following conversion code to convert UTC format string to any other DateTime format.

string result = Convert.ToDateTime("2011-02-04T00:00:00+05:30").ToString("MM/dd/yyyy h:mm:ss tt");

If you specify the datacolumn date time mode unspecified then it won''t append that +5:30 hours.

myDateColumn.DateTimeMode = System.Data.DataSetDateTime.Unspecified;

However it is better to consider the UTC offset if users from different time zone enter the data. For that need to store the data in a common time format then convert to any zone at the time of display. Can substract the +5:30 offset, so get the meridian time and store. Later may convert to IST and display. If the data input from a same timezone then just ignore the UTC offset.


这篇关于将数据集转换为XML时如何在Xml中更改Dateformat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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