C#时间日期处理及版本处理

1 DateTime 日期格式

语法示例(2016-05-09 13:09:55:2350)格式说明
DateTime.Now.ToString(““yyyy-MM-dd HH:mm:ss.ff””)2016-05-09 13:09:55.45自定义格式
DateTime.Now.ToString()2016/5/9 13:09:55短日期 长时间
DateTime.Now.ToString(“d”)2016/5/9短日期
DateTime.Now.ToString(“D”)2016年5月9日长日期
DateTime.Now.ToString(“f”)2016年5月9日 13:09长日期 短时间
DateTime.Now.ToString(“F”)2016年5月9日 13:09:55长日期 长时间
DateTime.Now.ToString(“g”)2016/5/9 13:09短日期 短时间
DateTime.Now.ToString(“G”)2016/5/9 13:09:55短日期 长时间
DateTime.Now.ToString(“t”)13:09短时间
DateTime.Now.ToString(“T”)13:09:55长时间
DateTime.Now.ToString(“u”)2016-05-09 13:09:55Z
DateTime.Now.ToString(“U”)2016年5月9日 5:09:55本初子午线的长日期和长时间
DateTime.Now.ToString(“m”)5月9日
DateTime.Now.ToString(“M”)5月9日
DateTime.Now.ToString(“r”)Mon, 09 May 2016 13:09:55 GMT
DateTime.Now.ToString(“R”)Mon, 09 May 2016 13:09:55 GMT
DateTime.Now.ToString(“y”)2016年5月
DateTime.Now.ToString(“Y”)2016年5月
DateTime.Now.ToString(“o”)2016-05-09T13:09:55.2350000
DateTime.Now.ToString(“O”)2016-05-09T13:09:55.2350000
DateTime.Now.ToString(“s”)2016-05-09T13:09:55

2 记录项目的最后编译时间

System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location)

C++中,有个__DATE__,TIMEFILE,__LINE__这样的异性宏定义可以使用,但是在C#中,不能使用

3 C#获取程序集的版本号:

using System.Reflection;
string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();//assembly version
string ver = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).FileVersion; //file version

4 C# Debug和Release模式运行不同代码

#if DEBUG 
ver = ver + "-debug";
#else

#endif

点击菜单中的"project",选择当前工程的属性"properties"中
debug模式勾选Define DEBUG constant
release模式取消勾选Define DEBUG constant
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fwsylin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值