首页 > 编程语言 >C# 时间各种格式

C# 时间各种格式

时间:2022-12-08 20:00:42浏览次数:33  
标签:各种 string currentTime C# strT int ToString 当前 格式

1.1 取当前年月日时分秒
 currentTime=System.DateTime.Now;
 1.2 取当前年
 int 年=currentTime.Year;
 1.3 取当前月
 int 月=currentTime.Month;
 1.4 取当前日
 int 日=currentTime.Day;
 1.5 取当前时
 int 时=currentTime.Hour;
 1.6 取当前分
 int 分=currentTime.Minute;
 1.7 取当前秒
 int 秒=currentTime.Second;
 1.8 取当前毫秒
 int 毫秒=currentTime.Millisecond; 
 1.9 取中文日期显示——年月日时分
 string strY=currentTime.ToString("f"); //不显示秒
 1.10 取中文日期显示_年月
 string strYM=currentTime.ToString("y");
 1.11 取中文日期显示_月日
 string strMD=currentTime.ToString("m");
 1.12 取中文年月日
 string strYMD=currentTime.ToString("D");
 1.13 取当前时分,格式为:14:24
 string strT=currentTime.ToString("t");
 1.14 取当前时间,格式为:2003-09-23T14:46:48
 string strT=currentTime.ToString("s");
 1.15 取当前时间,格式为:2003-09-23 14:48:30Z
 string strT=currentTime.ToString("u");
 1.16 取当前时间,格式为:2003-09-23 14:48
 string strT=currentTime.ToString("g");
 1.17 取当前时间,格式为:Tue, 23 Sep 2003 14:52:40 GMT
 string strT=currentTime.ToString("r");
 1.18 取当前时间,格式为:Tue, 23 Sep 2003 14:52:40 GMT+0800
 string strT=currentTime.ToString("r")+"0800";

  

标签:各种,string,currentTime,C#,strT,int,ToString,当前,格式
From: https://www.cnblogs.com/SmallChen/p/16967127.html

相关文章

  • STM32驱动HC-SR04 超声波测距模块(HAL)
     输入捕获主要参考这位大佬链接:https://blog.csdn.net/as480133937/article/details/99407485一、HC-SR04简单介绍HC-SR04超声波模块常用于机器人避障、物体测距、液位......
  • C语言《程序设计基础课程设计》题库
    C语言《程序设计基础课程设计》题库要求:学生须按学号最后两位选择对应题目。采用单链表和文件实现系统。具体实现要求:(1)从文件中读出数据,创建带头结点的单链表;......
  • C++ pair
    1.头文件pair函数存在于C++标准库#include<utility>中。2.用处他可以创建一个有2个成员的结构体。3.使用方法它的使用方法是:pair<数据类型1,数据类型2>结构体变量......
  • torch.tensor.to()
    tensor=torch.randn(2,2)#Initiallydtype=float32,device=cputensor.to(torch.float64)cuda0=torch.device('cuda:0')tensor.to(cuda0)tensor.to(cuda0......
  • 使用nc进行tcp测速
    #servernc-lIPPORT>/dev/nulleg:nc-l192.168.144.18080>/dev/null#clientbs单位块大小count块数量,bs不要太大不然内存不够ddif=/dev/zerobs=104857......
  • ServletContext_获取以及获取MIME类型
    ServletContext_获取以及获取MIME类型1.获取:1.通过request对象获取request.getServletContext();2.通过HTTPServlet获取this.getServletConte......
  • CodeSandbox
    网站https://codesandbox.io/新建的时候有各种模版可以选择,也可以从GitHub导入项目,也可以把自己的项目作为模版方便下次直接fork默认会存放在﹝Mydrafts﹞中,也可以在﹝All......
  • 用HTML+CSS做一个漂亮简单大学生校园班级网页
    OverridetheentrypointofanimageIntroducedinGitLabandGitLabRunner9.4.Readmoreaboutthe extendedconfigurationoptions.Beforeexplainingtheav......
  • 用HTML CSS 实现简洁美观的时间线(历史年表)
    前几天在B站刷到尼尔后突发奇想,就想给尼尔做一个简单的小网站,在思考如何体现尼尔的世界观的时候想到了使用时间线的方式,将所有时间的事件罗列起来。所以就试着做了一下,这种......
  • Docker 安装MySql 8.0
    1.下载镜像dockerpullmysql:8.0.312.安装dockerrun-p3306:3306--namemysql8-v/fanqi/mysql/conf:/etc/mysql/conf.d-v/fanqi/mysql/logs:/logs-v/fanqi......