C# txt格式记录时间,时间对比,决定是否更新代码记录Demo
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的更多相关文章
- 3天时间从零到上架AppStore流程记录
3天时间从零到上架AppStore流程记录 清明假期刚过去一周,我如愿以偿把自己想要的一个App上架了AppStore 从有idea到技术选型,从设计稿到框架开发,从提审AppStore到上架一共经历 ...
- C#中 String 格式的日期时间 转为 DateTime
C#中并没有表示时间的变量,只有DateTime,所以要表示时间,可以用TimeSpan表示. 方法一:Convert.ToDateTime(string) string格式有要求,必须是yyyy-M ...
- javascript两行代码按指定格式输出日期时间
javascript两行代码按指定格式输出日期时间,具体看代码: function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1 ...
- Python 将一个时间戳格式化为(格林威治时间或者本地时区时间)
时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数. 获取一个时间戳 import time times = time. ...
- UTCformat 转换UTC时间并格式化成本地时间
/** * UTCformat 转换UTC时间并格式化成本地时间 * @param {string} utc */ UTCformat (utc) { var date = new Date(utc) ...
- Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组
Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组 import time dt=time.strptime('2019-08-08 11:32:23', ...
- js 当前时间和对比时间的比较
<!DOCTYPE><html> <head> <meta charset="utf-8" /> <title>功能:当 ...
- 会话技术之cookie(记录当前时间、浏览记录的记录和清除)
cookie 会话技术: 当用户打开浏览器的时候,访问不同的资源,直到用户将浏览器关闭,可以认为这是一次会话. 作用: 因为http协议是一个无状态的协议,它不会记录上一次访问的内容.用户在访问过程中 ...
- Python-时间戳、元组时间的格式、自定义时间格式之间的转换
一.时间戳.元组时间的格式.自定义时间格式之间的转换 1.下面是三者之间的转换关系: 2.代码如下: import time import datetime print(time.time()) #获 ...
随机推荐
- beeline vs hive cli
近期,大数据开发环境升级为cloudera 5.3. 配套的hive版本升级为0.13.1.可以使用心仪已久的分析开窗函数了.但在使用的过程中发现一些问题,仅记于此. 1.在使用hive命令的时候,发 ...
- WordCount Analysis
1.Create a new java project, then copy examples folder from /home/hadoop/hadoop-1.0.4/src; Create a ...
- Legendre polynomials
In mathematics, Legendre functions are solutions to Legendre's differential equation: In particular, ...
- [cocos2dx] 让UIButton支持disable状态
摘要: 主要解决cocos2dx-2.2.2版本中, UIButton显示不了disable状态图的问题. 顺便, 理解了一下cocos2dx中UIWidget的渲染原理. 博客: http://ww ...
- 【实践】jdbc批量插入数据
参考文献:http://my.oschina.net/u/1452675/blog/203670 http://superjavason.iteye.com/blog/255423 /*测试批量写入数 ...
- Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA
题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路 ...
- MySQL数据库学习笔记(三)----基本的SQL语句
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
- AutoIT脚本的语法特征
这里主要介绍AutoIT的脚本语法特征,包括变量.关键字.宏.设置选项等,详细的语法细节,可以参考其用户手册,也可以去AutoIT中文论坛(www.autoit.net.cn)交流. 1. 变量 Au ...
- WebService wsdl没有types的问题
刚学WebService就遇到一个问题,按视屏敲的代码,它生成的wsdl页面与自己的不一样,我的没有types,结构完全不同了 This XML file does not appear to hav ...
- 基于Nodejs生态圈的TypeScript+React开发入门教程
基于Nodejs生态圈的TypeScript+React开发入门教程 概述 本教程旨在为基于Nodejs npm生态圈的前端程序开发提供入门讲解. Nodejs是什么 Nodejs是一个高性能Ja ...