c# - c#格式化数据写入csv文件
问题描述
我的 C# 非常有限,我的英语也很有限。我需要你的帮助。我需要从条形码阅读器编辑数据。像这样的传入数据。
1-) 12345678(条码) 2-) 310319(日期 dmy 格式) 3-) 174252(时分秒) 4-) 123 (条形码) 5-) 010419(日期 dmy 格式) 6-) 153020 (时分秒) 7-) 3873 (代码)
好的,这是我来自条形码阅读器的数据。我想按如下方式格式化这些数据。
最终输出是这样的样本。对不起,我的英语不好,你能帮帮我吗
1-) 12345678(条码不变) 2-)2和3行时间戳(310319 + 174252)?时间戳 3-) 123(条码不变) 4-) 5 和 6 行时间戳 (010419 + 153020) ?到时间戳 5-) 3873 (不变)
string name = lvw.SubItems[1].Text = Splt[0];
string filePath = @"C:\Temp\data.csv";
var one = lvw.SubItems[1].Text = Splt[0];
var two = lvw.SubItems[1].Text = Splt[1];
var three = lvw.SubItems[1].Text = Splt[2];
var four = lvw.SubItems[1].Text = Splt[3];
var five = lvw.SubItems[1].Text = Splt[4];
var six = lvw.SubItems[1].Text = Splt[5];
var seven = lvw.SubItems[1].Text = Splt[6];
var data = one +";" + two + ";" + three + ";"
+ four + ";" + five + ";" + six + ";" + seven + Environment.NewLine;
File.AppendAllText(filePath, data);
变量二 + 三结合时间戳这是我的问题吗?
解决方案
string date = "310319";
string time = "174252";
DateTime dt;
bool correct = DateTime.TryParseExact(date + time,
"ddMMyyHHmmss",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal,
out dt);
Console.WriteLine(dt);
DateTimeOffset dto = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
dto = new DateTimeOffset(dt, TimeSpan.Zero);
long y = dto.ToUnixTimeSeconds();
Console.WriteLine(y); // output 1554054172
谢谢大家。这就是我解决问题的方法。
推荐阅读
- php - 在 codeigniter 上显示数组数据复选框
- neo4j - JavaAPI 的 XML 的 APOC 过程
- r - R:x轴/axis.POSIXct()函数上显示的时间
- javascript - jQuery将活动类添加到第三个动态创建的div
- google-sheets - 在运行 BigQuery 作业之前确定资源使用情况
- scala - Spark MLLIB:计算随机森林回归的标准差值
- oracle-apex-5 - Oracle 顶点开发-INT-PROD
- graphql - 是否可以使用 graphql 多次查询同一个字段
- c++ - 在 C++11 中获取/释放 VS 顺序一致性?
- configuration - .Net Core 2.0 为多个环境配置 Appsettings