取時間的年月日時分秒

2021-05-27 22:52:31 字數 1647 閱讀 8492

c#中 取時間的年月日時分秒

1:時間格式轉換

system.datetime currenttime=new system.datetime();

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獲得當前時間 n 天後的日期時間

datetime newday = datetime.now.adddays(100);

1.19將2006-8-7 9:13:45------>2006/08/07 09:13

lblnow.text =system.datetime.now.tostring("yyyy/mm/dd hh:mm").replace("-","/");

string data1=convert.todatetime(dtpkfrom.text.trim()).tostring("yyyy-mm-dd ");

string data2=convert.todatetime(dtpkto.text.trim()).tostring("yyyy-mm-dd ");

獲取年月日時分秒

calendar ca calendar.getinstance int year ca.get calendar.year 獲取年份 2016 system.out.println year int month ca.get calendar.month 獲取月份 10 1 system.out....

python年月日時分秒

通過datetime函式獲取 import datetime 取當前時間 print datetime.datetime.now 取年 print datetime.datetime.now year 取月 print datetime.datetime.now month 取日 print dat...

C 中 取時間的年月日時分秒

c 中 取時間的年月日時分秒 1 時間格式轉換 system.datetime currenttime new system.datetime 1.1 取當前年月日時分秒 currenttime system.datetime.now 1.2 取當前年 int 年 currenttime.year ...