以UTC格式从XML格式化时间

时间:2019-02-04 11:00:28

标签: c# xml

我在加载从服务器上的程序接收到的XML时遇到问题,即服务器加载了UTC时间,并且我从Excel中获得了时间,现在我需要一个生成时间为(夏季为一小时)的XML。 )和(冬季每隔两个小时)。在有人将XML转换为向后移动一小时后,是否可以在我的代码部分中添加一些内容? (UTC时间)

这是我的代码:

  private void buttonSaveXml_Click(object sender, EventArgs e)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            //settings.Encoding = new UTF8Encoding(false);
            settings.Encoding = Encoding.UTF8;
            settings.Encoding = Encoding.GetEncoding("utf-8");
            settings.Indent = true;

            XmlWriter xmlWriter = XmlWriter.Create(PATH, settings);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("Event_Information");
            xmlWriter.WriteAttributeString("Data_Set_Type", "REPLACE");

            xmlWriter.WriteStartElement("Service");
            xmlWriter.WriteAttributeString("Name", "LeuTV");
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }
                else
                {
                    xmlWriter.WriteStartElement("Event");
                    xmlWriter.WriteAttributeString("Start", row.Cells[0].Value + " " + row.Cells[1].Value);
                    xmlWriter.WriteAttributeString("end-time", (string)row.Cells[2].Value);
                    xmlWriter.WriteStartElement("short-event-descriptor");
                    xmlWriter.WriteAttributeString("Language", "deu");
                    xmlWriter.WriteStartElement("Name");
                    xmlWriter.WriteString((string)row.Cells[3].Value);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("extended-event-descriptor");
                    xmlWriter.WriteAttributeString("Language", "deu");
                    xmlWriter.WriteStartElement("Text");
                    xmlWriter.WriteString((string)row.Cells[4].Value);
                    xmlWriter.WriteFullEndElement();
                    xmlWriter.WriteFullEndElement();
                    xmlWriter.WriteFullEndElement();
                }
            }
            xmlWriter.WriteEndDocument();
            xmlWriter.Close();
            MessageBox.Show("Inserted successfully!!");
        }

这两行代码为我设置了开始时间和结束时间,如果可以的话,我现在要将其移回UTC一个小时?

            xmlWriter.WriteAttributeString("Start", row.Cells[0].Value + " " + row.Cells[1].Value);
            xmlWriter.WriteAttributeString("end-time", (string)row.Cells[2].Value);

非常感谢大家

0 个答案:

没有答案