问题描述
parameterlist4是2016-10-13T09:27:35.000Z
解析后,我得到2016-10-13T09:27:35然后添加1秒
myDateTimetest = 2016-10-13T09:27:36(添加秒)
然后我将其转换为"o"格式,它给了我"2016-10-13T09:27:36.0000000Z"字符串
我必须使用哪种格式来获取此格式的时间戳"2016-10-13T09:27:36.000Z"?
谢谢.
我尝试过的事情:
DateTime myDateTime = DateTime.Parse(parameterlist4);
var myDateTimetest = myDateTime.ToUniversalTime();
for(int i = 0; i< 90; i ++)
{
//string timestampadd = Convert.ToString(myDateTime);
字符串timestampadd = myDateTimetest.ToString("0");
SnapshotDateTimenew [i] = timestampadd;
myDateTimetest = myDateTimetest.AddSeconds(1);
}
parameterlist4 is 2016-10-13T09:27:35.000Z
After parsing I am getting 2016-10-13T09:27:35 then adding 1 second
myDateTimetest = 2016-10-13T09:27:36 (Add Seconds)
Then I am converting it to "o" format it gives me "2016-10-13T09:27:36.0000000Z" string
which format do I have to use to get timestamp in this format "2016-10-13T09:27:36.000Z"?
Thank you.
What I have tried:
DateTime myDateTime = DateTime.Parse(parameterlist4);
var myDateTimetest = myDateTime.ToUniversalTime();
for (int i = 0; i < 90; i++)
{
//string timestampadd = Convert.ToString (myDateTime);
string timestampadd = myDateTimetest.ToString("0");
SnapshotDateTimenew[i] = timestampadd;
myDateTimetest = myDateTimetest.AddSeconds(1);
}
推荐答案
string myFormat = myDateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
这篇关于格式化时间戳C#..的问题不想尾随零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!