1 Star 0 Fork 0

猪头痴人/LearnCSharp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LearnDate.cs 3.38 KB
一键复制 编辑 原始数据 按行查看 历史
ronal 提交于 2021-11-08 21:10 . 学习代码更新。
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);
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ZhuTouChiRen/learn-csharp.git
git@gitee.com:ZhuTouChiRen/learn-csharp.git
ZhuTouChiRen
learn-csharp
LearnCSharp
master

搜索帮助