文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > C#获取当前系统时间
侵权投诉

C#获取当前系统时间

C#获取当前系统时间

C#获取当前系统时间
--DateTime 数字型
System.DateTime currentTime=new System.DateTime();
取当前年月日时分秒 currentTime=System.DateTime.Now;
取当前年 int 年=currentTime.Year;
取当前月 int 月=currentTime.Month;
取当前日 int 日=currentTime.Day;
取当前时 int 时=currentTime.Hour;
取当前分 int 分=currentTime.Minute;
取当前秒 int 秒=currentTime.Second;
取当前毫秒 int 毫秒=currentTime.Millisecond; (变量可用中文)

取中文日期显示——年月日时分 string strY=currentTime.ToString("f"); //不显示秒

取中文日期显示_年月 string strYM=currentTime.ToString("y");

取中文日期显示_月日 string strMD=currentTime.ToString("m");

取当前年月日,格式为:2003-9-23 string strYMD=currentTime.ToString("d");

取当前时分,格式为:14:24 string strT=currentTime.ToString("t");

DateTime.Now.ToString();//获取当前系统时间 完整的日期和时间
DateTime.Now.ToLongDateString();//只显示日期 xxxx年xx月xx日 ,一个是长日期
DateTime.Now.ToShortDateString();//只显示日期 xxxx-xx-xx 一个是短日期

//今天 DateTime.Now.Date.ToShortDateString();
//昨天 的 DateTime.Now.AddDays(-1).ToShortDateString();
//明天 的 DateTime.Now.AddDays(1).ToShortDateString();


//本周(注意这里的每一周是从周日始至周六止)
DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();

//上周,上周就是本周再减去7天

DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek))) - 7).ToShortDateString();
DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek))) - 7).ToShortDateString();

//下周 本周再加上7天

DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek))) + 7).ToShortDateString();
DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek))) + 7).ToShortDateString();

//本月 本月的第一天是1号,最后一天就是下个月一号再减一天。

DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + "1"; //第一天
DateTime.Parse(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + "1").AddMonths(1).AddDays(-1).ToShortDateString();//最后一天

另一种方法:

DateTime now = DateTime.Now;
DateTime d1 = new DateTime(now.Year, now.Month, 1); //本月第一天

DateTime d2 = d1.AddMonths(1).AddDays(-1); //本月最后一天

PS:


DateTime.Now.DayOfWeek.ToString();//英文星期显示,Wednesday

(int)DateTime.Now.DayOfWeek 数字,若是周三,结果对应为3

DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("zh-cn")); //中文星期显

第1页

你可能喜欢

  • vc获取当前时间
  • 获取系统时间ip
  • php获取当前时间
  • js获取系统当前时间
  • mfc获取当前时间
  • 获取当前时间

热门文档

相关文档

  • C#获取系统时间

    C#获取系统时间_IT/计算机_专业资料。C#的各种系统时间命令:年月日时分秒,年度,...C#获取当前系统时间 3页 免费 C语言获取系统时间的几种... 5页 免费 获取系统...

  • Unity3d 获取当前系统时间

    Unity3d 获取当前系统时间_计算机软件及应用_IT/计算机_专业资料。Unity3d 获取当前...用C获得当前系统时间 4页 1下载券 C++获取系统时间的方法 2页 1下载券 获取...

  • net获取系统当前时间

    net获取系统当前时间_IT/计算机_专业资料。net获取系统当前时间.txt.net获取系统当前时间 收藏 在c# / ASP.net中我们可以通过使用DataTime这个类来获取当前的时间。...

  • C#获取系统时间

    C#获取当前系统时间 3页 免费 C语言获取系统时间的几种... 5页 免费 获取系统时间代码 暂无评价 4页 免费 获取系统时间示例 暂无评价 2页 免费 取得系统时间 ...

  • Java各种获取系统当前时间方法和格式

    www.bj-accp.com Java 各种获取系统当前时间方法和格式 想索取更多相关资料请加 qq:649085085 或登录 http://www.bj-accp.com PS;本文档由北大青鸟广安门收集...

  • C#获取当前程序运行目录

    C#获取当前程序运行目录_电脑基础知识_IT/计算机_专业资料。zlC#获取当前程序运行...如何用vc 获取系统时间... 7页 免费 提高C程序运行效率 3页 免费 AD两通道...

  • MFC获取系统当前时间

    1.使用CTime类 CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime(); str=tm.Format("现在时间是%Y年%m月%d日 %X"); MessageBox(str,...

  • C语言获取当前系统时间的几种方式

    *** //用标准 C 实现获取当前系统时间的函数 一.time()函数 time(&rawtime)函数获取当前时间距1970年1月1日的秒数,以秒计数单位,存于 rawtime 中。 #inclu...

  • 用C获得当前系统时间

    用C获得当前系统时间_IT/计算机_专业资料。使用C语言获得系统时间的方法和代码#include <stdio.h> #include void main () { time_t rawtime; struct tm *...

  • C语言获取当前系统时间的几种方式

    *** //用标准C实现获取当前系统时间的函数 一.time()函数 time(&rawtime)函数获取当前时间距1970年1月1日的秒数,以秒计数单位,存于rawtime 中。 #include...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email