代码拉取完成,页面将自动刷新
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
namespace LearnCSharp_1
{
class LearnDate
{
static void Main_LearnDate(string[] args)
{
DateTime now = DateTime.Now;
Console.WriteLine(now.ToString("F")); // F说明符创建完整的日期和时间模式。
Console.ReadKey();
string[] months = { "January", "February", "March", "April", "May", "June", "July", "September", "October", "November", "December" };
Console.WriteLine("Today's date: {0}", now.Date);
Console.WriteLine("Today is {0} day of {1}", now.Day, months[now.Month - 1]);
Console.WriteLine("Today is {0} day of {1}", now.DayOfYear, now.Year);
Console.WriteLine("Today's time: {0}", now.TimeOfDay);
Console.WriteLine("Hour: {0}", now.Hour);
Console.WriteLine("Minute: {0}", now.Minute);
Console.WriteLine("Second: {0}", now.Second);
Console.WriteLine("Millisecond: {0}", now.Millisecond);
Console.WriteLine("The day of week: {0}", now.DayOfWeek);
Console.WriteLine("Kind: {0}", now.Kind);
Console.ReadKey();
DateTime dt = new DateTime(2019, 2, 22, 14, 0, 0);
DateTime dt1 = dt.AddSeconds(55);
DateTime dt2 = dt.AddMinutes(30);
DateTime dt3 = dt.AddHours(72);
DateTime dt4 = dt.AddDays(65);
DateTime dt5 = dt.AddDays(-65);
DateTime dt6 = dt.AddMonths(3);
DateTime dt7 = dt.AddYears(4);
Console.WriteLine(dt1.ToString("F"));
Console.WriteLine(dt2.ToString("F"));
Console.WriteLine(dt3.ToString("F"));
Console.WriteLine(dt4.ToString("F"));
Console.WriteLine(dt5.ToString("F"));
Console.WriteLine(dt6.ToString("F"));
Console.WriteLine(dt7.ToString("F"));
DateTime utc = DateTime.UtcNow;
Console.WriteLine($"UTC time {utc:HH:mm:ss}");
Console.ReadKey();
Console.OutputEncoding = System.Text.Encoding.UTF8;
CultureInfo ci = new CultureInfo("sk-SK");
Console.WriteLine($"Dnesny datum a cas: {now.ToString("F", ci)}");
Console.ReadKey();
string startTime = "7:00 AM";
string endTime = "8:30 PM";
TimeSpan elapsed = DateTime.Parse(endTime).Subtract(DateTime.Parse(startTime));
Console.WriteLine($"Time elapsed: {elapsed}");
Console.ReadKey();
DateTime borodino_battle = new DateTime(1812, 9, 7);
TimeSpan diff = DateTime.Today - borodino_battle;
Console.WriteLine($"{diff.TotalDays} days have passed since the Battle of Borodino.");
// 获得本地时区
TimeZoneInfo localZone = TimeZoneInfo.Local;
Console.WriteLine("Current timezone: {0}", localZone.StandardName); // 时区的标准名称
Console.WriteLine("Daylight name: {0}", localZone.DaylightName); // 时区的夏令名称
Console.WriteLine("Bias: {0}", localZone.BaseUtcOffset);
Console.ReadKey();
var timezones = TimeZoneInfo.GetSystemTimeZones();
foreach (var timezone in timezones)
{
Console.WriteLine(timezone.Id);
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。