Skip to content

Commit 12bffec

Browse files
committed
Add TimeCrontabExercise
1 parent c5fcf0c commit 12bffec

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

DotNetExercises.sln

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ VisualStudioVersion = 17.8.34330.188
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuestPDFExercise", "QuestPDFExercise\QuestPDFExercise.csproj", "{95C92BAB-39B9-4724-8F22-566A22302AC6}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoMapperExercise", "AutoMapperExercise\AutoMapperExercise.csproj", "{AC5D3877-7A7E-4543-A393-D639D03596FD}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoMapperExercise", "AutoMapperExercise\AutoMapperExercise.csproj", "{AC5D3877-7A7E-4543-A393-D639D03596FD}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeCrontabExercise", "TimeCrontabExercise\TimeCrontabExercise.csproj", "{E976663E-3CE4-4FCA-83F7-8AA338A023E6}"
911
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,6 +23,10 @@ Global
2123
{AC5D3877-7A7E-4543-A393-D639D03596FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{AC5D3877-7A7E-4543-A393-D639D03596FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{AC5D3877-7A7E-4543-A393-D639D03596FD}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{E976663E-3CE4-4FCA-83F7-8AA338A023E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{E976663E-3CE4-4FCA-83F7-8AA338A023E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{E976663E-3CE4-4FCA-83F7-8AA338A023E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{E976663E-3CE4-4FCA-83F7-8AA338A023E6}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

TimeCrontabExercise/Program.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using TimeCrontab;
2+
3+
namespace TimeCrontabExercise
4+
{
5+
internal class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
//常规格式:分 时 天 月 周
10+
var crontab = Crontab.Parse("* * * * *");
11+
var nextOccurrence = crontab.GetNextOccurrence(DateTime.Now);
12+
13+
//支持年份:分 时 天 月 周 年
14+
var crontab1 = Crontab.Parse("* * * * * *", CronStringFormat.WithYears);
15+
var nextOccurrence1 = crontab1.GetNextOccurrence(DateTime.Now);
16+
17+
//支持秒数:秒 分 时 天 月 周
18+
var crontab2 = Crontab.Parse("* * * * * *", CronStringFormat.WithSeconds);
19+
var nextOccurrence2 = crontab2.GetNextOccurrence(DateTime.Now);
20+
21+
//支持秒和年:秒 分 时 天 月 周 年
22+
var crontab3 = Crontab.Parse("* * * * * * *", CronStringFormat.WithSecondsAndYears);
23+
var nextOccurrence3 = crontab3.GetNextOccurrence(DateTime.Now);
24+
25+
// Macro 字符串
26+
var secondly = Crontab.Parse("@secondly"); //每秒 [* * * * * *]
27+
var minutely = Crontab.Parse("@minutely"); //每分钟 [* * * * *]
28+
var hourly = Crontab.Parse("@hourly"); //每小时 [0 * * * *]
29+
var daily = Crontab.Parse("@daily"); //每天 00:00:00 [0 0 * * *]
30+
var monthly = Crontab.Parse("@monthly"); //每月 1 号 00:00:00 [0 0 1 * *]
31+
var weekly = Crontab.Parse("@weekly"); //每周日 00:00:00 [0 0 * * 0]
32+
var yearly = Crontab.Parse("@yearly"); //每年 1 月 1 号 00:00:00 [0 0 1 1 *]
33+
var workday = Crontab.Parse("@workday"); //每周一至周五 00:00:00 [0 0 * * 1-5]
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="TimeCrontab" Version="3.3.6" />
12+
</ItemGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)