Fork me on GitHub

至简

Be simple

为了寻找你,我把自己搬进鸟的眼睛,经常盯着路过的风。


C#代码片段


1、时间戳

var ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
long times = Convert.ToInt64(ts.TotalMilliseconds);
DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime date = start.AddMilliseconds(times).ToLocalTime();
//时区转换
string ID = TimeZoneInfo.Local.Id;
DateTime startTime = TimeZoneInfo.ConvertTime(date, TimeZoneInfo.FindSystemTimeZoneById(ID));
string formattedDate = startTime.ToString("yyyy-MM-dd_HH_mm_ss.fff");

2、写文本

string file_path = "";//要写入的路径
System.IO.StreamWriter m_loc_file = new System.IO.StreamWriter(file_path, true, Encoding.UTF8);
m_loc_file.WriteLine("Hello world!");
m_loc_file.Flush();
m_loc_file.Close();