zoukankan      html  css  js  c++  java
  • 【实验室笔记】C#以本地时间创建txt文件

      前段时间做的一个小项目,要求上位机在打开时候,以打开软件的系统时间的建立一个txt文件来存储下位机发送来的数据。

      在第一版上位机上,取名的办法太弱了,先是读取系统时间,然后截取字符串,太笨拙。昨天,查了查资料,

    发现了C#自身就可以清楚地读出时间。

    1 System.DateTime.Now.Year
    2 System.DateTime.Now.Month
    3 System.DateTime.Now.Day
    4 System.DateTime.Now.Hour
    5 System.DateTime.Now.Minute
    6 System.DateTime.Now.Second

      为了保证数据的对其格式比如1不够十位,为了显示出01效果,采用PadLeft(2, '0')即可。

    string str = System.DateTime.Now.Year.ToString().PadLeft(2, '0') + System.DateTime.Now.Month.ToString().PadLeft(2, '0')
                           + System.DateTime.Now.Day.ToString().PadLeft(2, '0') + System.DateTime.Now.Hour.ToString().PadLeft(2, '0')
                           + System.DateTime.Now.Minute.ToString().PadLeft(2, '0') + System.DateTime.Now.Second.ToString().PadLeft(2, '0');
  • 相关阅读:
    爬取豆瓣电影信息
    MongoDB的聚合操作以及与Python的交互
    matplotlib简单示例
    MongoDB基本操作
    K近邻算法
    Scrapy爬取博客园精华区内容
    爬虫失败
    Markdown基本使用方法
    UITableViewCell高度自适应变化
    KVO和NSNotification
  • 原文地址:https://www.cnblogs.com/achao123456/p/6131350.html
Copyright © 2011-2022 走看看