从服务器获取时间和日期!!!(实时) [英] get time and date from server!!!(real time)

查看:583
本文介绍了从服务器获取时间和日期!!!(实时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取日期时间
但是我写了这段代码
例子;
system.datetime.now.day
它让我度过了系统的一天
我想要服务器的日期(实际时间)

i want get the date time
but i writed this code
example ;
system.datetime.now.day
and it geted me day of my system
i want date of server (realy time)

推荐答案

DateTime today = DateTime.Now;

这将获取当前日期和时间放入变量today中-然后可以使用所需的部分:
today.Day是一个月中的某天,
today.Month是一年中的月份,
today.Hour是一天中的小时,
today.Minute是小时中的分钟.

可能是您希望将其转换为字符串以显示,所以请使用ToString方法:

This gets the current date and time into the variable today - you can then use what parts of it you need:
today.Day is the day of the month,
today.Month is the month of the year,
today.Hour is the hour of the day,
today.Minute is the minute of the hour.

Probably, you want to convert this to a string for display, so use the ToString method:

string timeIn12HourClock = today.ToString("hh:mm");
string timeIn24HourClock = today.ToString("HH:mm");



您可以使用或构造许多其他格式:格式化a显示的日期时间-格式字符串说明 [



There are load of other formats you can use or construct: Formatting a DateTime for display - format string description[^]


这篇关于从服务器获取时间和日期!!!(实时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆