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()) #获 ...
随机推荐
- 关于macOS Sierra无法使用gdb进行调试的解决方案
1.对gdb进行签名,签名过程详见:http://jingyan.baidu.com/article/d169e1864dc24d436611d839.html: 2.重新启动系统,同时按住键盘上的c ...
- gdb 远程调试 android native 程序
ilocker:关注 Android 安全(新入行,0基础) QQ: 2597294287 先看一张原理图: 我是 Linux 和 Android 双料 0 基础,目前对 gdb 了解的很浅显.(注意 ...
- Java + eclipse + awt 编写锻炼打字小软件(未完成)
进入前界面: import java.awt.*; public class Welcome extends JFrame implements Runnable{ Thread t; private ...
- 多人操作sqlite3数据库冲突问题解决方法
问题描述:sqlite3数据放置在某一台电脑的某个共享文件夹下,操作数据库的应用程序安装在同一局域网下的很多台电脑上,由于存在多人同时使用该应用程序,所以存在多人同时操作数据库的情况.经过测试发现,最 ...
- 【读书笔记《Android游戏编程之从零开始》】11.游戏开发基础(SurfaceView 游戏框架、View 和 SurfaceView 的区别)
1. SurfaceView 游戏框架实例 实例效果:就是屏幕上的文本跟着点击的地方移动,效果图如下: 步骤: 新建项目“GameSurfaceView”,首先自定义一个类"MySurfac ...
- 算法最坏,平均和最佳情况(Worst, Average and Best Cases)-------geeksforgeeks 翻译
最坏,平均和最佳运行时间(Worst, Average and Best Cases) 在上一篇文章中,我们讨论到了渐进分析可以解决分析算法的问题,那么在这一篇中,我们用线性搜索来举例说明一下如何用渐 ...
- Android网络之数据解析----使用Google Gson解析Json数据
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- Android SQLite (三 ) 全面详解(一)
官网 SQLite是一款轻型的数据库,是关系型数据库(RDBMS)管理系统,它包含在一个相对小的C库中.目前在很多嵌入式产品中使用了它,它占用资源非常 的低,在嵌入式设备中,可能只需要几百K的内存就够 ...
- CSS padding margin border属性
主要定义四个区域:内容(content).内边距(padding).边框(border)和外边距(margin) margin:层的边框以外留的空白 background-color:背景颜色 bac ...
- 项目管理和缺陷跟踪工具Redmine
官网: http://www.redmine.org/ http://demo.redmine.org/ 下载: http://www.redmine.org/projects/redmine/wik ...