using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _6_13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnSaveData_Click(object sender, EventArgs e)
{
SaveFileDialog sfDlg = new SaveFileDialog(); //保存文件对话框
sfDlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); //打开文件时默认显示程序所在的文件夹
string date_time = Convert.ToString(DateTime.Now); //这个属性能够返回当前操作系统的本地日期和时间。2023-06-13 22:31:49
date_time = date_time.Remove(10); //2023-06-13
string real_time = Convert.ToString(DateTime.Now.TimeOfDay); //22:29:05.5210537
real_time = real_time.Remove(8); //22:29:05
real_time = real_time.Replace(":", "点"); //22点29点05
real_time = real_time.Remove(5, 1); //22点2905
real_time = real_time.Insert(5, "分"); //22点29分05
sfDlg.FileName = date_time + "_" + real_time + "秒"; //2023-06-13_23点29分05秒
sfDlg.DefaultExt = ".asc"; //2023-06-13_23点29分05秒.asc
if (sfDlg.ShowDialog() == DialogResult.OK)
{
btnSaveData.Enabled = false;
btnStopData.Enabled = true;
FileStream fs = new FileStream(sfDlg.FileName, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
string dateInfo = DateInfo();
sw.WriteLine(dateInfo);
string txtInfo = "base hex timestamps absolute" + "\r\n" + "internal events logged" + "\r\n";
sw.WriteLine(txtInfo);
sw.Flush(); //将缓冲区中的数据立即写入到文件
sw.Close();
fs.Close();
}
}
public string DateInfo()
{
string ret = "";
int mon = DateTime.Now.Month;
string[] month = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
string time = Convert.ToString(DateTime.Now.TimeOfDay);
time = time.Substring(0, time.Length - 14);
int hour = Convert.ToInt16(time);
if (hour >= 0 && hour <= 12)
{
time = "AM";
}
else if (hour > 12 && hour <= 24)
{
time = "PM";
}
ret = "data " + Convert.ToString(DateTime.Now.DayOfWeek).Remove(3) + " " + month[mon - 1] + " "
+ Convert.ToString(DateTime.Now.Day) + " " + Convert.ToString(DateTime.Now).Substring(11) + " " + time + " "
+ Convert.ToString(DateTime.Now.Year);
return ret;
}
private void btnStopData_Click(object sender, EventArgs e)
{
}
}
}
saveDlg
最新推荐文章于 2024-08-24 15:52:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)