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()) #获 ...
随机推荐
- pushd
# MAN 手册原文: pushd [-n] [+n] [-n] pushd [-n] [dir] Adds a directory to ...
- nagios 自定义插件demo
#!/bin/bash loadavg=$( uptime | awk -F: '{print $4}' | xargs ) load1int=$( ) load5int=$( ) load15int ...
- django模型
用django时,只要用到数据库就得用到模型. 一.数据库的MTV开发模式 从MVC到MTV 所谓软件架构的MVC模式将数据的存取逻辑(Module),表现逻辑(View)和业务逻辑(Controll ...
- MIT jos 6.828 Fall 2014 训练记录(lab 6)
源代码参见我的github: https://github.com/YaoZengzeng/jos 在这个实验中将实现一个基于Intel 82540M(又称E1000)的网卡驱动.不过,一个网卡驱动还 ...
- 通过CDC获取 HDC
通过CDC获取HDC 通过CDC(设备描述表)获取HDC(设备上下文句柄)的方法: //第一种 void ...::OnDraw(CDC *pDC) { ...... HDC hDC=pDC-> ...
- Codeforces Round #266 (Div.2) B Wonder Room --枚举
题意:给出一个两边长为a,b的矩形,要求增加a和增加b使a*b>=6*n且a*b最小. 解法:设新的a,b为a1,b1,且设a<b,那么a<=a1<=ceil(sqrt(6*n ...
- 第17章 内存映射文件(3)_稀疏文件(Sparse File)
17.8 稀疏调拨的内存映射文件 17.8.1 稀疏文件简介 (1)稀疏文件(Sparse File):指的是文件中出现大量的0数据,这些数据对我们用处不大,但是却一样的占用空间.NTFS文件系统对此 ...
- uGUI练习(一) Anchor
一.练习步骤 如果用过NGUI的Anchor,我们知道在2.x的版本有UIAnchor组件(下图左),3.x版本中,每个UIWidget有自带的Anchors(下图右) 而uGUI的Anchor用起来 ...
- Windows环境中Openfire与Spark安装与配置指南
安装软件: openfire3.9.3 spark2.6.3 安装环境: WindowsXP JDK1.6.0_21 Oracle 一.openfire安装 1.安装openfire3.9.3,下载地 ...
- [ORACLE错误]ORA-00054:resource busy and acquire with nowait specified解决方法
当某个数据库用户在数据库中插入.更新.删除一个表的数据,或者增加一个表的主键时或者表的索引时,常常会出现ora-00054:resource busy and acquire with nowait ...