Submitchanges中的DateTime UTC Converion() [英] DateTime UTC Converion in Submitchanges()
本文介绍了Submitchanges中的DateTime UTC Converion()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在linq中进行日期时间UTC转换在.net应用程序中提交更改方法?
先谢谢
Hi,
How to do Datetime UTC Convertion in linq Submit changes method in .net Application?
Thanks in Advance
推荐答案
示例:
Example:
var rows = ds.Tables["client"].AsEnumerable().Select(row => new { id = row["id"], utc = ((DateTime)row["dob"]).ToUniversalTime() });
此示例使用新属性id和utc创建一个新的对象数组列表。您可以使用已知的类类型替换它,或者使用以创建包含utc中所有数据的新列表。
替换所有日期时间一次性完成这样做:
首先获得所有日期时间字段的结果,
This example creates a new object array list with new properties 'id' and 'utc'. You can replace this with a known class type or use to create a new list with all data in utc.
To replace all date time fields in one go, do this:
first get a result of all the date time fields,
var dateTimeFields = from column in ds.Tables["client"].Columns.Cast<DataColumn>()
where column.DataType == typeof(DateTime)
select column;
then set the new value for each Datetime field in each row:
foreach (var row in ds.Tables["client"].AsEnumerable())
foreach (var field in dateTimeFields)
row.SetField(field.ColumnName, row.Field<DateTime>(field.ColumnName).ToUniversalTime());
这篇关于Submitchanges中的DateTime UTC Converion()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文