using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; namespace fileIO
{
class Program
{
static void Main(string[] args)
{
string filename =AppDomain.CurrentDomain.BaseDirectory+ "companyUpdateLog.txt";
if (File.Exists(filename))
{
string time=ReadLog(filename);
if (time != "") {
DateTime dt;
if (DateTime.TryParse(time, out dt)) {
DateTime dtnow = DateTime.Now;
int days = (dtnow - dt).Days;
if (days == 7)
{
//开始更新
Console.WriteLine("正在更新");
WriteLog(filename, dtnow.ToString("yyyy-MM-dd HH:mm:ss"));
}
else {
Console.WriteLine("无需更新");
}
}
}
}
else {
DateTime dtnow = DateTime.Now;
//开始更新
Console.WriteLine("文件不存在时候:正在更新");
WriteLog(filename, dtnow.ToString("yyyy-MM-dd HH:mm:ss"));
} Console.ReadLine();
} public static void WriteLog(string path,string text) {
using (FileStream file = new FileStream(path, FileMode.OpenOrCreate))
{
StreamWriter sw = new StreamWriter(file);
sw.Write(text);
sw.Close();
}
}
public static string ReadLog(string path)
{
string a="";
using (FileStream file = new FileStream(path, FileMode.Open))
{
StreamReader sw = new StreamReader(file);
a=sw.ReadToEnd();
sw.Close();
}
return a;
}

  

C# txt格式记录时间,时间对比,决定是否更新代码记录Demo的更多相关文章

  1. 3天时间从零到上架AppStore流程记录

    3天时间从零到上架AppStore流程记录 清明假期刚过去一周,我如愿以偿把自己想要的一个App上架了AppStore 从有idea到技术选型,从设计稿到框架开发,从提审AppStore到上架一共经历 ...

  2. C#中 String 格式的日期时间 转为 DateTime

    C#中并没有表示时间的变量,只有DateTime,所以要表示时间,可以用TimeSpan表示. 方法一:Convert.ToDateTime(string) string格式有要求,必须是yyyy-M ...

  3. javascript两行代码按指定格式输出日期时间

    javascript两行代码按指定格式输出日期时间,具体看代码: function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1 ...

  4. Python 将一个时间戳格式化为(格林威治时间或者本地时区时间)

    时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数. 获取一个时间戳 import time times = time. ...

  5. UTCformat 转换UTC时间并格式化成本地时间

    /** * UTCformat 转换UTC时间并格式化成本地时间 * @param {string} utc */ UTCformat (utc) { var date = new Date(utc) ...

  6. Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组

    Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组 import time dt=time.strptime('2019-08-08 11:32:23', ...

  7. js 当前时间和对比时间的比较

    <!DOCTYPE><html> <head> <meta charset="utf-8" /> <title>功能:当 ...

  8. 会话技术之cookie(记录当前时间、浏览记录的记录和清除)

    cookie 会话技术: 当用户打开浏览器的时候,访问不同的资源,直到用户将浏览器关闭,可以认为这是一次会话. 作用: 因为http协议是一个无状态的协议,它不会记录上一次访问的内容.用户在访问过程中 ...

  9. Python-时间戳、元组时间的格式、自定义时间格式之间的转换

    一.时间戳.元组时间的格式.自定义时间格式之间的转换 1.下面是三者之间的转换关系: 2.代码如下: import time import datetime print(time.time()) #获 ...

随机推荐

  1. C++ 第一个C++程序

    #include <iostream> // C++自带的标准头文件都是没有.h的 // 就相当于C语言的<stdio.h> // 提前使用命名空间std using name ...

  2. Swift 语法笔记01

    Swift 好多新奇的地方啊...妈的 var display: int { get() set() } Tuple: let x: (d:Double, e:String, f:Int) = (3. ...

  3. AD批量创建用户

    实验环境:Windows Server 2008R 2 由于测试需要,需要创建数百个用户,手动创建当然不可取,此时需要批量创建,操作记录如下 1 首先将要批量创建的人员信息导入到一个csv文件中,表中 ...

  4. codeforces 442C C. Artem and Array(贪心)

    题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. hdu-5521 Meeting(最短路)

    题目链接: Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  6. codeforces 721C C. Journey(dp)

    题目链接: C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  7. [cb]NGUI组件基类之 UIWidget

    UIWidget NGUI的UIWidget是所有组件的基类,它承担了存储显示内容,颜色调配,显示深度,显示位置,显示大小,显示角度,显示的多边形形状,归属哪个UIPanel.这就是UIWidget所 ...

  8. Linux+Mono+Asp.net入门:05CentOs安装Mono(上)

    http://www.cnblogs.com/jameszou/archive/2013/05/18/3085754.html 准备工作 常见问题 a. Xshell显示中文乱码问题 [文件]–> ...

  9. [本人开发的游戏] Discuz网页动物园插件1.0Beta发布!让积分流动起来!

        插件发布 插件名称: DZ网页动物园插件 插件来源: 原创插件 适用版本: Discuz! X3 语言编码: GBK简体 UTF8简体 BIG5繁体 UTF8繁体  最后更新时间: 2014- ...

  10. Android Studio 三种添加插件的方式,androidstudio

    前几篇blog我们介绍了如何安装和配置Android Studio,这篇Blog我们来聊聊如何给Android Studio添加插件,添加插件的路径有三种,我把他们分类如下: 点击设置小按钮 点击[P ...