【问题标题】:DateTime format for the DateTime field in Sharepoint ListSharepoint 列表中 DateTime 字段的 DateTime 格式
【发布时间】:2018-02-06 17:52:35
【问题描述】:

我正在处理需要将日期从一个列表迁移到另一个列表的项目。我的源列表的日期时间格式为 MM/DD/YY,我的目标列表字段的日期时间格式为 DD/MM/YY。当我在目的地解析值时,它的转换不正确。

从列表字段中读取值的代码。

ClientContext ctx = new ClientContext(targetURL);
ctx.Credentials = new SharePointOnlineCredentials(userName, passWord);

ctx.Load(ctx.Web);
SP.ListCollection listCol = web.Lists;
ctx.Load(listCol);

SP.List list = listCollection.GetByTitle("ListTitle");

SP.CamlQuery camlQuery = new SP.CamlQuery();
camlQuery.ViewXml = "";

SP.ListItemCollection listItemCollection = list.GetItems(camlQuery);
ctx.Load(listItemCollection);

//Execute Query 
ctx.ExecuteQuery();
foreach (ListItem _item in listItemCollection)
{
    ctx.Load(_item,tmp => tmp.FieldValuesAsHtml);
    ctx.ExecuteQuery();
    foreach (var fieldValue in _item.FieldValuesAsHtml.FieldValues)
    {
        string _value  = fieldValue.Value; //for datetime field returning value as string
    }

}

在目标列表中将 _Value 转换为日期时间

    destItem["Date"]= Convert.ToDateTime(_value);
//date is getting changed as DateTime format is diffrent.

如何获取源列表的 DateTime 格式?

【问题讨论】:

    标签: sharepoint sharepoint-online csom


    【解决方案1】:

    我终于得到了答案。我们可以使用区域设置属性获取日期时间格式。

    ClientContext.Load(f_Web, website => website.RegionalSettings)
    ClientContext.ExecuteQuery();
    var format = f_Web.RegionalSettings.DateFormat;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-02
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      相关资源
      最近更新 更多