元编程参考文档

日期时间操作

138 个节点

本页内容 138

加上时间间隔

函数

重载 1/4

签名
加上时间间隔(值: 时间日期, 增量: TimeSpan) -> 时间日期
DateTime Add(DateTime value, TimeSpan delta)

给时间日期加上一段时间间隔。

参数

名称类型默认值说明
值时间日期—
增量TimeSpan—

返回

结果时间日期

重载 2/4

签名
加上时间间隔(值: TimeOnly, 增量: TimeSpan) -> TimeOnly
TimeOnly Add(TimeOnly value, TimeSpan delta)

给时刻加上一段时间间隔。

参数

名称类型默认值说明
值TimeOnly—
增量TimeSpan—

返回

结果TimeOnly

重载 3/4

签名
加上时间间隔 -> (结果: TimeOnly, 跨越天数: 整数)
    值: TimeOnly
    增量: TimeSpan
TimeOnly Add(
    TimeOnly value,
    TimeSpan delta,
    out int wrappedDays)

给时刻加上一段时间间隔,越过午夜时绕回,并报告钟表绕过了几天。

参数

名称类型默认值说明
值TimeOnly—The starting time of day.
增量TimeSpan—The duration to add; negative moves back.

返回

结果TimeOnly
跨越天数整数

重载 4/4

签名
加上时间间隔(左侧: TimeSpan, 右侧: TimeSpan) -> TimeSpan
TimeSpan Add(TimeSpan left, TimeSpan right)

把两个时间间隔相加。

参数

名称类型默认值说明
左侧TimeSpan—
右侧TimeSpan—

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

加天数

函数

重载 1/2

签名
加天数(值: 时间日期, 天数: 数字) -> 时间日期
DateTime AddDays(DateTime value, double days)

把时间日期按天数前后移动,天数可以是小数(0.5 即十二小时)。

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
天数数字—The number of days to add; negative moves back.

返回

结果时间日期

重载 2/2

签名
加天数(值: DateOnly, 天数: 整数) -> DateOnly
DateOnly AddDays(DateOnly value, int days)

给日期加上若干天。

参数

名称类型默认值说明
值DateOnly—
天数整数—

返回

结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

加小时数

函数

重载 1/3

签名
加小时数(值: 时间日期, 小时数: 数字) -> 时间日期
DateTime AddHours(DateTime value, double hours)

把时间日期按小时数前后移动,可以是小数。

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
小时数数字—The number of hours to add; negative moves back.

返回

结果时间日期

重载 2/3

签名
加小时数(值: TimeOnly, 小时数: 数字) -> TimeOnly
TimeOnly AddHours(TimeOnly value, double hours)

把时刻按小时数前后移动,越过午夜时绕回(22:00 加 3 小时为 01:00)。

参数

名称类型默认值说明
值TimeOnly—The starting time of day.
小时数数字—The number of hours to add, which may be fractional or negative.

返回

结果TimeOnly

重载 3/3

签名
加小时数 -> (结果: TimeOnly, 跨越天数: 整数)
    值: TimeOnly
    小时数: 数字
TimeOnly AddHours(
    TimeOnly value,
    double hours,
    out int wrappedDays)

把时刻按小时数前后移动,越过午夜时绕回,并报告钟表绕过了几天。

参数

名称类型默认值说明
值TimeOnly—The starting time of day.
小时数数字—The number of hours to add, which may be fractional or negative.

返回

结果TimeOnly
跨越天数整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

加微秒数

函数

把时间日期按微秒数前后移动,可以是小数。

签名
加微秒数(值: 时间日期, 微秒数: 数字) -> 时间日期
DateTime AddMicroseconds(DateTime value, double microseconds)

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
微秒数数字—The number of microseconds to add; negative moves back.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

加毫秒数

函数

把时间日期按毫秒数前后移动,可以是小数。

签名
加毫秒数(值: 时间日期, 毫秒数: 数字) -> 时间日期
DateTime AddMilliseconds(DateTime value, double milliseconds)

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
毫秒数数字—The number of milliseconds to add; negative moves back.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

加分钟数

函数

重载 1/3

签名
加分钟数(值: 时间日期, 分钟数: 数字) -> 时间日期
DateTime AddMinutes(DateTime value, double minutes)

把时间日期按分钟数前后移动,可以是小数。

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
分钟数数字—The number of minutes to add; negative moves back.

返回

结果时间日期

重载 2/3

签名
加分钟数(值: TimeOnly, 分钟数: 数字) -> TimeOnly
TimeOnly AddMinutes(TimeOnly value, double minutes)

把时刻按分钟数前后移动,越过午夜时绕回。

参数

名称类型默认值说明
值TimeOnly—The starting time of day.
分钟数数字—The number of minutes to add, which may be fractional or negative.

返回

结果TimeOnly

重载 3/3

签名
加分钟数 -> (结果: TimeOnly, 跨越天数: 整数)
    值: TimeOnly
    分钟数: 数字
TimeOnly AddMinutes(
    TimeOnly value,
    double minutes,
    out int wrappedDays)

把时刻按分钟数前后移动,越过午夜时绕回,并报告钟表绕过了几天。

参数

名称类型默认值说明
值TimeOnly—The starting time of day.
分钟数数字—The number of minutes to add, which may be fractional or negative.

返回

结果TimeOnly
跨越天数整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

加月数

函数

重载 1/2

签名
加月数(值: 时间日期, 月数: 整数) -> 时间日期
DateTime AddMonths(DateTime value, int months)

把时间日期按整月前后移动,时刻保持不变。

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
月数整数—The number of months to add, from -120000 to 120000; negative moves back.

返回

结果时间日期

备注

If the day does not exist in the target month it is clamped to that month's last day, so January 31 plus one month is February 28 (or 29 in a leap year).

重载 2/2

签名
加月数(值: DateOnly, 月数: 整数) -> DateOnly
DateOnly AddMonths(DateOnly value, int months)

把日期按整月前后移动。

参数

名称类型默认值说明
值DateOnly—The starting date.
月数整数—The number of months to add; negative moves back.

返回

结果DateOnly

备注

If the day does not exist in the target month it is clamped to that month's last day, so January 31 plus one month is February 28 (or 29 in a leap year).

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

加秒数

函数

把时间日期按秒数前后移动,可以是小数。

签名
加秒数(值: 时间日期, 秒数: 数字) -> 时间日期
DateTime AddSeconds(DateTime value, double seconds)

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
秒数数字—The number of seconds to add; negative moves back.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

加计时周期数

函数

把时间日期按计时周期数前后移动,一个计时周期为 100 纳秒。

签名
加计时周期数(值: 时间日期, 计时周期数: 大整数) -> 时间日期
DateTime AddTicks(DateTime value, long ticks)

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
计时周期数大整数—The number of ticks to add; negative moves back.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

加年数

函数

重载 1/2

签名
加年数(值: 时间日期, 年数: 整数) -> 时间日期
DateTime AddYears(DateTime value, int years)

把时间日期按整年前后移动,月、日和时刻保持不变。

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
年数整数—The number of years to add; negative moves back.

返回

结果时间日期

备注

February 29 moved to a year that is not a leap year becomes February 28.

重载 2/2

签名
加年数(值: DateOnly, 年数: 整数) -> DateOnly
DateOnly AddYears(DateOnly value, int years)

把日期按整年前后移动,月和日保持不变。

参数

名称类型默认值说明
值DateOnly—The starting date.
年数整数—The number of years to add; negative moves back.

返回

结果DateOnly

备注

February 29 moved to a year that is not a leap year becomes February 28.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

比较

函数

重载 1/4

签名
比较(左侧: 时间日期, 右侧: 时间日期) -> 整数
int Compare(DateTime left, DateTime right)

比较两个时间日期。

参数

名称类型默认值说明
左侧时间日期—
右侧时间日期—

返回

结果整数

备注

The comparison uses the underlying tick values and does not convert values based on DateTime.Kind.
To compare actual points in time, convert both values to UTC first.

重载 2/4

签名
比较(左侧: DateOnly, 右侧: DateOnly) -> 整数
int Compare(DateOnly left, DateOnly right)

比较两个日期。

参数

名称类型默认值说明
左侧DateOnly—
右侧DateOnly—

返回

结果整数

重载 3/4

签名
比较(左侧: TimeOnly, 右侧: TimeOnly) -> 整数
int Compare(TimeOnly left, TimeOnly right)

比较两个时刻。

参数

名称类型默认值说明
左侧TimeOnly—
右侧TimeOnly—

返回

结果整数

重载 4/4

签名
比较(左侧: TimeSpan, 右侧: TimeSpan) -> 整数
int Compare(TimeSpan left, TimeSpan right)

比较两个时间间隔。

参数

名称类型默认值说明
左侧TimeSpan—
右侧TimeSpan—

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

创建时间日期

函数

重载 1/8

签名
创建时间日期(计时周期数: 大整数) -> 时间日期
DateTime Create(long ticks)

用计时周期数创建时间日期。

参数

名称类型默认值说明
计时周期数大整数—

返回

结果时间日期

重载 2/8

签名
创建时间日期(计时周期数: 大整数, 种类: DateTimeKind) -> 时间日期
DateTime Create(long ticks, DateTimeKind kind)

用计时周期数创建时间日期,并标为本地时间、UTC 或未指定。

参数

名称类型默认值说明
计时周期数大整数—The number of 100-nanosecond ticks since 0001-01-01 00:00:00; must be between 0 and the ticks of DateTime.MaxValue, otherwise an System.ArgumentOutOfRangeException is thrown.
种类DateTimeKind—Whether the value is local time, UTC or unspecified.

返回

结果时间日期

重载 3/8

签名
创建时间日期(年: 整数, 月: 整数, 日: 整数) -> 时间日期
DateTime Create(int year, int month, int day)

创建给定日历日期午夜时分的时间日期。

参数

名称类型默认值说明
年整数—The year, from 1 to 9999.
月整数—The month, from 1 to 12.
日整数—The day of the month, from 1 to the number of days in that month.

返回

结果时间日期

重载 4/8

签名
创建时间日期 -> 时间日期
    年: 整数
    月: 整数
    日: 整数
    时: 整数
    分: 整数
    第二个: 整数
DateTime Create(
    int year,
    int month,
    int day,
    int hour,
    int minute,
    int second)

用日历日期和精确到秒的时刻创建时间日期。

参数

名称类型默认值说明
年整数—The year, from 1 to 9999.
月整数—The month, from 1 to 12.
日整数—The day of the month, from 1 to the number of days in that month.
时整数—The hour, from 0 to 23.
分整数—The minute, from 0 to 59.
第二个整数—The second, from 0 to 59.

返回

结果时间日期

重载 5/8

签名
创建时间日期 -> 时间日期
    年: 整数
    月: 整数
    日: 整数
    时: 整数
    分: 整数
    第二个: 整数
    种类: DateTimeKind
DateTime Create(
    int year,
    int month,
    int day,
    int hour,
    int minute,
    int second,
    DateTimeKind kind)

用日历日期和精确到秒的时刻创建时间日期,并标为本地时间、UTC 或未指定。

参数

名称类型默认值说明
年整数—The year, from 1 to 9999.
月整数—The month, from 1 to 12.
日整数—The day of the month, from 1 to the number of days in that month.
时整数—The hour, from 0 to 23.
分整数—The minute, from 0 to 59.
第二个整数—The second, from 0 to 59.
种类DateTimeKind—Whether the value is local time, UTC or unspecified.

返回

结果时间日期

重载 6/8

签名
创建时间日期 -> 时间日期
    年: 整数
    月: 整数
    日: 整数
    时: 整数
    分: 整数
    第二个: 整数
    毫秒: 整数
DateTime Create(
    int year,
    int month,
    int day,
    int hour,
    int minute,
    int second,
    int millisecond)

用日历日期和精确到毫秒的时刻创建时间日期。

参数

名称类型默认值说明
年整数—The year, from 1 to 9999.
月整数—The month, from 1 to 12.
日整数—The day of the month, from 1 to the number of days in that month.
时整数—The hour, from 0 to 23.
分整数—The minute, from 0 to 59.
第二个整数—The second, from 0 to 59.
毫秒整数—The millisecond, from 0 to 999.

返回

结果时间日期

重载 7/8

签名
创建时间日期 -> 时间日期
    年: 整数
    月: 整数
    日: 整数
    时: 整数
    分: 整数
    第二个: 整数
    毫秒: 整数
    种类: DateTimeKind
DateTime Create(
    int year,
    int month,
    int day,
    int hour,
    int minute,
    int second,
    int millisecond,
    DateTimeKind kind)

用日历日期和精确到毫秒的时刻创建时间日期,并标为本地时间、UTC 或未指定。

参数

名称类型默认值说明
年整数—The year, from 1 to 9999.
月整数—The month, from 1 to 12.
日整数—The day of the month, from 1 to the number of days in that month.
时整数—The hour, from 0 to 23.
分整数—The minute, from 0 to 59.
第二个整数—The second, from 0 to 59.
毫秒整数—The millisecond, from 0 to 999.
种类DateTimeKind—Whether the value is local time, UTC or unspecified.

返回

结果时间日期

重载 8/8

签名
创建时间日期 -> 时间日期
    年: 整数
    月: 整数
    日: 整数
    时: 整数
    分: 整数
    第二个: 整数
    毫秒: 整数
    微秒: 整数
    种类: DateTimeKind
DateTime Create(
    int year,
    int month,
    int day,
    int hour,
    int minute,
    int second,
    int millisecond,
    int microsecond,
    DateTimeKind kind = DateTimeKind.Unspecified)

用日历日期和精确到微秒的时刻创建时间日期,可标为本地时间或 UTC。

参数

名称类型默认值说明
年整数—The year, from 1 to 9999.
月整数—The month, from 1 to 12.
日整数—The day of the month, from 1 to the number of days in that month.
时整数—The hour, from 0 to 23.
分整数—The minute, from 0 to 59.
第二个整数—The second, from 0 to 59.
毫秒整数—The millisecond, from 0 to 999.
微秒整数—The microsecond, from 0 to 999.
种类DateTimeKindUnspecifiedWhether the value is local time, UTC or unspecified; unspecified when left out.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

创建日期

函数

重载 1/2

签名
创建日期(年: 整数, 月: 整数, 日: 整数) -> DateOnly
DateOnly CreateDateOnly(int year, int month, int day)

用年、月、日创建日期。

参数

名称类型默认值说明
年整数—
月整数—
日整数—

返回

结果DateOnly

重载 2/2

签名
创建日期 -> DateOnly
    年: 整数
    月: 整数
    日: 整数
    日历: Calendar
DateOnly CreateDateOnly(
    int year,
    int month,
    int day,
    Calendar calendar)

用另一种历法(如希伯来历或日本历)中的年、月、日创建日期。

参数

名称类型默认值说明
年整数—The year in Calendar.
月整数—The month in Calendar.
日整数—The day of the month in Calendar.
日历Calendar—The calendar the year, month and day are expressed in; must not be null.

返回

结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

创建时刻

函数

重载 1/4

签名
创建时刻(时: 整数, 分: 整数) -> TimeOnly
TimeOnly CreateTimeOnly(int hour, int minute)

用时和分创建时刻。

参数

名称类型默认值说明
时整数—
分整数—

返回

结果TimeOnly

重载 2/4

签名
创建时刻(时: 整数, 分: 整数, 第二个: 整数) -> TimeOnly
TimeOnly CreateTimeOnly(int hour, int minute, int second)

用时、分、秒创建时刻。

参数

名称类型默认值说明
时整数—The hour, from 0 to 23.
分整数—The minute, from 0 to 59.
第二个整数—The second, from 0 to 59.

返回

结果TimeOnly

重载 3/4

签名
创建时刻 -> TimeOnly
    时: 整数
    分: 整数
    第二个: 整数
    毫秒: 整数
TimeOnly CreateTimeOnly(
    int hour,
    int minute,
    int second,
    int millisecond)

用时、分、秒、毫秒创建时刻。

参数

名称类型默认值说明
时整数—The hour, from 0 to 23.
分整数—The minute, from 0 to 59.
第二个整数—The second, from 0 to 59.
毫秒整数—The millisecond, from 0 to 999.

返回

结果TimeOnly

重载 4/4

签名
创建时刻 -> TimeOnly
    时: 整数
    分: 整数
    第二个: 整数
    毫秒: 整数
    微秒: 整数
TimeOnly CreateTimeOnly(
    int hour,
    int minute,
    int second,
    int millisecond,
    int microsecond)

用时、分、秒、毫秒、微秒创建时刻。

参数

名称类型默认值说明
时整数—The hour, from 0 to 23.
分整数—The minute, from 0 to 59.
第二个整数—The second, from 0 to 59.
毫秒整数—The millisecond, from 0 to 999.
微秒整数—The microsecond, from 0 to 999.

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

创建时间间隔

函数

重载 1/5

签名
创建时间间隔(计时周期数: 大整数) -> TimeSpan
TimeSpan CreateTimeSpan(long ticks)

用计时周期数创建时间间隔。

参数

名称类型默认值说明
计时周期数大整数—

返回

结果TimeSpan

重载 2/5

签名
创建时间间隔(小时数: 整数, 分钟数: 整数, 秒数: 整数) -> TimeSpan
TimeSpan CreateTimeSpan(int hours, int minutes, int seconds)

用时、分、秒创建时间间隔。

参数

名称类型默认值说明
小时数整数—The number of hours.
分钟数整数—The number of minutes.
秒数整数—The number of seconds.

返回

结果TimeSpan

备注

The parts are added together, so they may exceed their usual ranges or be negative: 0 hours, 90 minutes and 0 seconds is one and a half hours. An System.ArgumentOutOfRangeException is thrown if the total is beyond TimeSpan.MaxValue or TimeSpan.MinValue.

重载 3/5

签名
创建时间间隔 -> TimeSpan
    天数: 整数
    小时数: 整数
    分钟数: 整数
    秒数: 整数
TimeSpan CreateTimeSpan(
    int days,
    int hours,
    int minutes,
    int seconds)

用天、时、分、秒创建时间间隔。

参数

名称类型默认值说明
天数整数—The number of days.
小时数整数—The number of hours.
分钟数整数—The number of minutes.
秒数整数—The number of seconds.

返回

结果TimeSpan

备注

The parts are added together, so they may exceed their usual ranges or be negative. An System.ArgumentOutOfRangeException is thrown if the total is beyond TimeSpan.MaxValue or TimeSpan.MinValue.

重载 4/5

签名
创建时间间隔 -> TimeSpan
    天数: 整数
    小时数: 整数
    分钟数: 整数
    秒数: 整数
    毫秒数: 整数
TimeSpan CreateTimeSpan(
    int days,
    int hours,
    int minutes,
    int seconds,
    int milliseconds)

用天、时、分、秒、毫秒创建时间间隔。

参数

名称类型默认值说明
天数整数—The number of days.
小时数整数—The number of hours.
分钟数整数—The number of minutes.
秒数整数—The number of seconds.
毫秒数整数—The number of milliseconds.

返回

结果TimeSpan

备注

The parts are added together, so they may exceed their usual ranges or be negative. An System.ArgumentOutOfRangeException is thrown if the total is beyond TimeSpan.MaxValue or TimeSpan.MinValue.

重载 5/5

签名
创建时间间隔 -> TimeSpan
    天数: 整数
    小时数: 整数
    分钟数: 整数
    秒数: 整数
    毫秒数: 整数
    微秒数: 整数
TimeSpan CreateTimeSpan(
    int days,
    int hours,
    int minutes,
    int seconds,
    int milliseconds,
    int microseconds)

用天、时、分、秒、毫秒、微秒创建时间间隔。

参数

名称类型默认值说明
天数整数—The number of days.
小时数整数—The number of hours.
分钟数整数—The number of minutes.
秒数整数—The number of seconds.
毫秒数整数—The number of milliseconds.
微秒数整数—The number of microseconds.

返回

结果TimeSpan

备注

The parts are added together, so they may exceed their usual ranges or be negative. An System.ArgumentOutOfRangeException is thrown if the total is beyond TimeSpan.MaxValue or TimeSpan.MinValue.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

日期部分

函数

获取时间日期的日期部分。

签名
日期部分(值: 时间日期) -> 时间日期
DateTime Date(DateTime value)

参数

名称类型默认值说明
值时间日期—

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从时间日期取日期

函数

取时间日期的日历日期,去掉其时刻。

签名
从时间日期取日期(值: 时间日期) -> DateOnly
DateOnly DateOnlyFromDateTime(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time to take the date from; its kind is ignored and no time-zone conversion is made.

返回

结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从日序号取日期

函数

用天数编号创建日期,即公历中自 0001-01-01 起的天数。

签名
从日序号取日期(日序号: 整数) -> DateOnly
DateOnly DateOnlyFromDayNumber(int dayNumber)

参数

名称类型默认值说明
日序号整数—The number of days since 0001-01-01, from 0 (0001-01-01) to 3652058 (9999-12-31); any other value throws an System.ArgumentOutOfRangeException.

返回

结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

日

函数

重载 1/2

签名
日(值: 时间日期) -> 整数
int Day(DateTime value)

获取时间日期是当月的第几天。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
日(值: DateOnly) -> 整数
int Day(DateOnly value)

获取日期是当月的第几天。

参数

名称类型默认值说明
值DateOnly—The date.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

日序号

函数

把日期表示为一个天数编号,即自 0001-01-01 起的天数;两个天数编号相减即为两者相隔的天数。

签名
日序号(值: DateOnly) -> 整数
int DayNumber(DateOnly value)

参数

名称类型默认值说明
值DateOnly—The date.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

星期几

函数

重载 1/2

签名
星期几(值: 时间日期) -> DayOfWeek
DayOfWeek DayOfWeek(DateTime value)

获取时间日期是星期几。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果DayOfWeek

重载 2/2

签名
星期几(值: DateOnly) -> DayOfWeek
DayOfWeek DayOfWeek(DateOnly value)

获取日期是星期几。

参数

名称类型默认值说明
值DateOnly—The date.

返回

结果DayOfWeek
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

一年中的第几天

函数

重载 1/2

签名
一年中的第几天(值: 时间日期) -> 整数
int DayOfYear(DateTime value)

获取时间日期是当年的第几天。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
一年中的第几天(值: DateOnly) -> 整数
int DayOfYear(DateOnly value)

获取日期是当年的第几天。

参数

名称类型默认值说明
值DateOnly—The date.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

天数

函数

获取时间间隔的天数部分。

签名
天数(值: TimeSpan) -> 整数
int Days(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

相隔天数

函数

计算从一个日期到另一个日期相隔的日历天数。

签名
相隔天数(左侧: DateOnly, 右侧: DateOnly) -> 整数
int DaysBetween(DateOnly left, DateOnly right)

参数

名称类型默认值说明
左侧DateOnly—The later date.
右侧DateOnly—The earlier date.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

月份天数

函数

给出公历中某年某月的天数,已考虑闰年。

签名
月份天数(年: 整数, 月: 整数) -> 整数
int DaysInMonth(int year, int month)

参数

名称类型默认值说明
年整数—The year, from 1 to 9999.
月整数—The month, from 1 to 12; any other value throws an System.ArgumentOutOfRangeException.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

分解

函数

重载 1/5

签名
分解(值: 时间日期) -> (年: 整数, 月: 整数, 日: 整数)
void Deconstruct(
    DateTime value,
    out int year,
    out int month,
    out int day)

把时间日期拆分为年、月、日。

参数

名称类型默认值说明
值时间日期—

返回

年整数
月整数
日整数

重载 2/5

签名
分解(值: 时间日期) -> (日期: DateOnly, 时间: TimeOnly)
void Deconstruct(
    DateTime value,
    out DateOnly date,
    out TimeOnly time)

把时间日期拆分为日历日期和时刻。

参数

名称类型默认值说明
值时间日期—The date and time to split; its kind is dropped and no time-zone conversion is made.

返回

日期DateOnly
时间TimeOnly

重载 3/5

签名
分解(值: DateOnly) -> (年: 整数, 月: 整数, 日: 整数)
void Deconstruct(
    DateOnly value,
    out int year,
    out int month,
    out int day)

把日期拆分为年、月、日三个数。

参数

名称类型默认值说明
值DateOnly—The date to split.

返回

年整数
月整数
日整数

重载 4/5

签名
分解(值: TimeOnly) -> (时: 整数, 分: 整数, 第二个: 整数)
void Deconstruct(
    TimeOnly value,
    out int hour,
    out int minute,
    out int second)

把时刻拆分为时、分、秒;不足一秒的部分舍去。

参数

名称类型默认值说明
值TimeOnly—The time of day to split.

返回

时整数
分整数
第二个整数

重载 5/5

签名
分解(值: TimeSpan) -> (天数: 整数, 小时数: 整数, 分钟数: 整数, 秒数: 整数)
void Deconstruct(
    TimeSpan value,
    out int days,
    out int hours,
    out int minutes,
    out int seconds)

把时间间隔拆分为整天、时、分、秒;不足一秒的部分舍去,负的时间间隔各部分均为负。

参数

名称类型默认值说明
值TimeSpan—The duration to split.

返回

天数整数
小时数整数
分钟数整数
秒数整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

除以

函数

重载 1/2

签名
除以(值: TimeSpan, 除数: 数字) -> TimeSpan
TimeSpan Divide(TimeSpan value, double divisor)

用一个数去除时间间隔,例如把它等分。

参数

名称类型默认值说明
值TimeSpan—The duration to divide.
除数数字—The number to divide by; NaN throws an System.ArgumentException, and zero throws an System.OverflowException.

返回

结果TimeSpan

重载 2/2

签名
除以(左侧: TimeSpan, 右侧: TimeSpan) -> 数字
double Divide(TimeSpan left, TimeSpan right)

给出两个时间间隔之比,例如一个能容纳几个另一个。

参数

名称类型默认值说明
左侧TimeSpan—The duration to divide.
右侧TimeSpan—The duration to divide by; zero gives infinity, or NaN when Left is also zero, instead of an error.

返回

结果数字
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

绝对时长

函数

取时间间隔的绝对长度,去掉其正负号。

签名
绝对时长(值: TimeSpan) -> TimeSpan
TimeSpan Duration(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration; TimeSpan.MinValue throws an System.OverflowException because its absolute value does not fit.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

相等

函数

重载 1/4

签名
相等(左侧: 时间日期, 右侧: 时间日期) -> 真否
bool Equals(DateTime left, DateTime right)

检查两个时间日期是否相同。

参数

名称类型默认值说明
左侧时间日期—The first date and time.
右侧时间日期—The second date and time.

返回

结果真否

备注

Only the tick values are compared and DateTime.Kind is ignored, so a local and a UTC value with the same clock reading are equal. Convert both to UTC first to compare actual points in time.

重载 2/4

签名
相等(左侧: DateOnly, 右侧: DateOnly) -> 真否
bool Equals(DateOnly left, DateOnly right)

检查两个日期是否是同一天。

参数

名称类型默认值说明
左侧DateOnly—The first date.
右侧DateOnly—The second date.

返回

结果真否

重载 3/4

签名
相等(左侧: TimeOnly, 右侧: TimeOnly) -> 真否
bool Equals(TimeOnly left, TimeOnly right)

检查两个时刻是否相同,精确到计时周期。

参数

名称类型默认值说明
左侧TimeOnly—The first time of day.
右侧TimeOnly—The second time of day.

返回

结果真否

重载 4/4

签名
相等(左侧: TimeSpan, 右侧: TimeSpan) -> 真否
bool Equals(TimeSpan left, TimeSpan right)

检查两个时间间隔是否一样长,精确到计时周期。

参数

名称类型默认值说明
左侧TimeSpan—The first duration.
右侧TimeSpan—The second duration.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从二进制值还原

函数

从“转为二进制值”生成的数字还原时间日期,连同其时间类型。

签名
从二进制值还原(值: 大整数) -> 时间日期
DateTime FromBinary(long value)

参数

名称类型默认值说明
值大整数—The packed number; one that does not encode a valid date throws an System.ArgumentException.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

由日期和时刻组合

函数

重载 1/2

签名
由日期和时刻组合(日期: DateOnly, 时间: TimeOnly) -> 时间日期
DateTime FromDateOnlyTimeOnly(DateOnly date, TimeOnly time)

把日期和时刻合成一个时间日期。

参数

名称类型默认值说明
日期DateOnly—
时间TimeOnly—

返回

结果时间日期

重载 2/2

签名
由日期和时刻组合 -> 时间日期
    日期: DateOnly
    时间: TimeOnly
    种类: DateTimeKind
DateTime FromDateOnlyTimeOnly(
    DateOnly date,
    TimeOnly time,
    DateTimeKind kind)

把一个日期和一个时刻合成一个时间日期,并标为本地时间、UTC 或未指定。

参数

名称类型默认值说明
日期DateOnly—The calendar date.
时间TimeOnly—The time of day on that date.
种类DateTimeKind—Whether the result is local time, UTC or unspecified.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从文件时间转换

函数

把 Windows 文件时间转换为本机所在时区的时间日期。

签名
从文件时间转换(值: 大整数) -> 时间日期
DateTime FromFileTime(long value)

参数

名称类型默认值说明
值大整数—The number of 100-nanosecond intervals since 1601-01-01 00:00:00 UTC; a negative or too-large value throws an System.ArgumentOutOfRangeException.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从 UTC 文件时间转换

函数

把 Windows 文件时间转换为 UTC 时间日期。

签名
从 UTC 文件时间转换(值: 大整数) -> 时间日期
DateTime FromFileTimeUtc(long value)

参数

名称类型默认值说明
值大整数—The number of 100-nanosecond intervals since 1601-01-01 00:00:00 UTC; a negative or too-large value throws an System.ArgumentOutOfRangeException.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从 OLE 自动化日期转换

函数

把 OLE 自动化日期(Excel 等 Office 应用表示日期所用的数字格式)转换为时间日期。

签名
从 OLE 自动化日期转换(值: 数字) -> 时间日期
DateTime FromOADate(double value)

参数

名称类型默认值说明
值数字—The number of days since 1899-12-30, with the time of day as the fraction; values outside -657435 to 2958466 (exclusive) throw an System.ArgumentException.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从 Unix 毫秒时间戳转换

函数

把 JavaScript 和许多 Web API 使用的毫秒级 Unix 时间戳转换回 UTC 时间日期。

签名
从 Unix 毫秒时间戳转换(毫秒数: 大整数) -> 时间日期
DateTime FromUnixTimeMilliseconds(long milliseconds)

参数

名称类型默认值说明
毫秒数大整数—The number of milliseconds since 1970-01-01 00:00:00 UTC, from -62135596800000 to 253402300799999; any other value throws an System.ArgumentOutOfRangeException.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从 Unix 秒时间戳转换

函数

把秒级 Unix 时间戳转换回 UTC 时间日期。

签名
从 Unix 秒时间戳转换(秒数: 大整数) -> 时间日期
DateTime FromUnixTimeSeconds(long seconds)

参数

名称类型默认值说明
秒数大整数—The number of seconds since 1970-01-01 00:00:00 UTC, from -62135596800 to 253402300799; any other value throws an System.ArgumentOutOfRangeException.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

日期最大值

函数

Gets the largest possible value of System.DateOnly.

签名
日期最大值() -> DateOnly
DateOnly DateOnlyMaxValue()

返回

结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

日期最小值

函数

Gets the smallest possible value of System.DateOnly.

签名
日期最小值() -> DateOnly
DateOnly DateOnlyMinValue()

返回

结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

最大值

函数

Gets the largest possible value of System.DateTime.

签名
最大值() -> 时间日期
DateTime MaxValue()

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

最小值

函数

Gets the smallest possible value of System.DateTime.

签名
最小值() -> 时间日期
DateTime MinValue()

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

每计时周期纳秒数

函数

Gets the number of nanoseconds in one tick.

签名
每计时周期纳秒数() -> 大整数
long NanosecondsPerTick()

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

现在

函数

Gets the current local date and time.

签名
现在() -> 时间日期
DateTime Now()

返回

结果时间日期

备注

The returned System.DateTime has DateTime.Kind set to DateTimeKind.Local.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

每天计时周期数

函数

Gets the number of ticks in one day.

签名
每天计时周期数() -> 大整数
long TicksPerDay()

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

每小时计时周期数

函数

Gets the number of ticks in one hour.

签名
每小时计时周期数() -> 大整数
long TicksPerHour()

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

每微秒计时周期数

函数

Gets the number of ticks in one microsecond.

签名
每微秒计时周期数() -> 大整数
long TicksPerMicrosecond()

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

每毫秒计时周期数

函数

Gets the number of ticks in one millisecond.

签名
每毫秒计时周期数() -> 大整数
long TicksPerMillisecond()

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

每分钟计时周期数

函数

Gets the number of ticks in one minute.

签名
每分钟计时周期数() -> 大整数
long TicksPerMinute()

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

每秒计时周期数

函数

Gets the number of ticks in one second.

签名
每秒计时周期数() -> 大整数
long TicksPerSecond()

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

时刻最大值

函数

Gets the largest possible value of System.TimeOnly.

签名
时刻最大值() -> TimeOnly
TimeOnly TimeOnlyMaxValue()

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

时刻最小值

函数

Gets the smallest possible value of System.TimeOnly.

签名
时刻最小值() -> TimeOnly
TimeOnly TimeOnlyMinValue()

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

时间间隔最大值

函数

Gets the largest possible value of System.TimeSpan.

签名
时间间隔最大值() -> TimeSpan
TimeSpan TimeSpanMaxValue()

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

时间间隔最小值

函数

Gets the smallest possible value of System.TimeSpan.

签名
时间间隔最小值() -> TimeSpan
TimeSpan TimeSpanMinValue()

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

零时间间隔

函数

Gets a zero-length System.TimeSpan.

签名
零时间间隔() -> TimeSpan
TimeSpan TimeSpanZero()

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

今天

函数

Gets the current local date with the time set to midnight.

签名
今天() -> 时间日期
DateTime Today()

返回

结果时间日期

备注

The returned System.DateTime has DateTime.Kind set to DateTimeKind.Local.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

Unix 纪元

函数

Gets the Unix epoch date and time: 1970-01-01 00:00:00 UTC.

签名
Unix 纪元() -> 时间日期
DateTime UnixEpoch()

返回

结果时间日期

备注

The returned System.DateTime has DateTime.Kind set to DateTimeKind.Utc.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

当前 UTC 时间

函数

Gets the current UTC date and time.

签名
当前 UTC 时间() -> 时间日期
DateTime UtcNow()

返回

结果时间日期

备注

The returned System.DateTime has DateTime.Kind set to DateTimeKind.Utc.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

获取时间日期格式

函数

重载 1/4

签名
获取时间日期格式(值: 时间日期) -> 文本数组
string[] GetDateTimeFormats(DateTime value)

用当前区域的每种标准格式写出时间日期,便于看出该选哪种格式。

参数

名称类型默认值说明
值时间日期—The date and time to format.

返回

结果文本数组

重载 2/4

签名
获取时间日期格式 -> 文本数组
    值: 时间日期
    提供者: IFormatProvider
string[] GetDateTimeFormats(
    DateTime value,
    IFormatProvider provider)

用给定区域的每种标准格式写出时间日期。

参数

名称类型默认值说明
值时间日期—The date and time to format.
提供者IFormatProvider—The culture whose conventions to use, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果文本数组

重载 3/4

签名
获取时间日期格式(值: 时间日期, 格式: Char) -> 文本数组
string[] GetDateTimeFormats(DateTime value, char format)

按当前区域中某一标准格式说明符的所有模式写出时间日期。

参数

名称类型默认值说明
值时间日期—The date and time to format.
格式Char—A standard format specifier such as 'd', 'D', 't' or 'G'; one that is not a standard specifier throws a System.FormatException.

返回

结果文本数组

重载 4/4

签名
获取时间日期格式 -> 文本数组
    值: 时间日期
    格式: Char
    提供者: IFormatProvider
string[] GetDateTimeFormats(
    DateTime value,
    char format,
    IFormatProvider provider)

按给定区域中某一标准格式说明符的所有模式写出时间日期。

参数

名称类型默认值说明
值时间日期—The date and time to format.
格式Char—A standard format specifier such as 'd', 'D', 't' or 'G'; one that is not a standard specifier throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to use, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果文本数组
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

大于

函数

重载 1/4

签名
大于(左侧: 时间日期, 右侧: 时间日期) -> 真否
bool GreaterThan(DateTime left, DateTime right)

检查一个时间日期是否晚于另一个。

参数

名称类型默认值说明
左侧时间日期—The date and time to test.
右侧时间日期—The date and time to compare against.

返回

结果真否

备注

Only the tick values are compared and DateTime.Kind is ignored.

重载 2/4

签名
大于(左侧: DateOnly, 右侧: DateOnly) -> 真否
bool GreaterThan(DateOnly left, DateOnly right)

检查一个日期是否在另一个之后。

参数

名称类型默认值说明
左侧DateOnly—The date to test.
右侧DateOnly—The date to compare against.

返回

结果真否

重载 3/4

签名
大于(左侧: TimeOnly, 右侧: TimeOnly) -> 真否
bool GreaterThan(TimeOnly left, TimeOnly right)

检查一个时刻是否晚于另一个,从午夜算起,不绕回。

参数

名称类型默认值说明
左侧TimeOnly—The time of day to test.
右侧TimeOnly—The time of day to compare against.

返回

结果真否

重载 4/4

签名
大于(左侧: TimeSpan, 右侧: TimeSpan) -> 真否
bool GreaterThan(TimeSpan left, TimeSpan right)

检查一个时间间隔是否比另一个长;负的时间间隔视为比零还短。

参数

名称类型默认值说明
左侧TimeSpan—The duration to test.
右侧TimeSpan—The duration to compare against.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

大于或等于

函数

重载 1/4

签名
大于或等于(左侧: 时间日期, 右侧: 时间日期) -> 真否
bool GreaterThanOrEqual(DateTime left, DateTime right)

检查一个时间日期是否晚于或等于另一个。

参数

名称类型默认值说明
左侧时间日期—The date and time to test.
右侧时间日期—The date and time to compare against.

返回

结果真否

备注

Only the tick values are compared and DateTime.Kind is ignored.

重载 2/4

签名
大于或等于(左侧: DateOnly, 右侧: DateOnly) -> 真否
bool GreaterThanOrEqual(DateOnly left, DateOnly right)

检查一个日期是否在另一个之后或与其是同一天。

参数

名称类型默认值说明
左侧DateOnly—The date to test.
右侧DateOnly—The date to compare against.

返回

结果真否

重载 3/4

签名
大于或等于(左侧: TimeOnly, 右侧: TimeOnly) -> 真否
bool GreaterThanOrEqual(TimeOnly left, TimeOnly right)

检查一个时刻是否晚于或等于另一个,从午夜算起,不绕回。

参数

名称类型默认值说明
左侧TimeOnly—The time of day to test.
右侧TimeOnly—The time of day to compare against.

返回

结果真否

重载 4/4

签名
大于或等于(左侧: TimeSpan, 右侧: TimeSpan) -> 真否
bool GreaterThanOrEqual(TimeSpan left, TimeSpan right)

检查一个时间间隔是否长于或等于另一个;负的时间间隔视为比零还短。

参数

名称类型默认值说明
左侧TimeSpan—The duration to test.
右侧TimeSpan—The duration to compare against.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

小时

函数

重载 1/2

签名
小时(值: 时间日期) -> 整数
int Hour(DateTime value)

获取时间日期的小时(24 小时制)。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
小时(值: TimeOnly) -> 整数
int Hour(TimeOnly value)

获取时刻的小时部分。

参数

名称类型默认值说明
值TimeOnly—

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

小时数

函数

获取时间间隔的小时部分,即去掉整天后剩下的部分;要得到整个时间间隔折合的小时数,请用“总小时数”。

签名
小时数(值: TimeSpan) -> 整数
int Hours(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

是否介于两者之间

函数

检查时刻是否落在某个范围内,包括 22:00 到 06:00 这样跨过午夜的范围。

签名
是否介于两者之间 -> 真否
    值: TimeOnly
    起点: TimeOnly
    终点: TimeOnly
bool IsBetween(TimeOnly value, TimeOnly start, TimeOnly end)

参数

名称类型默认值说明
值TimeOnly—The time of day to test.
起点TimeOnly—The start of the range, included.
终点TimeOnly—The end of the range, excluded; when earlier than Start the range runs through midnight.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

是否为夏令时

函数

检查时间日期是否处于本机所在时区的夏令时内。

签名
是否为夏令时(值: 时间日期) -> 真否
bool IsDaylightSavingTime(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time; a UTC value always gives false, and a local or unspecified value is read as local time.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

是否为闰年

函数

判断给定年份是否为闰年。

签名
是否为闰年(年: 整数) -> 真否
bool IsLeapYear(int year)

参数

名称类型默认值说明
年整数—

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

时间种类

函数

说明时间日期被标为本地时间、UTC 还是未指定。

签名
时间种类(值: 时间日期) -> DateTimeKind
DateTimeKind Kind(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time to inspect.

返回

结果DateTimeKind
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

小于

函数

重载 1/4

签名
小于(左侧: 时间日期, 右侧: 时间日期) -> 真否
bool LessThan(DateTime left, DateTime right)

检查一个时间日期是否早于另一个。

参数

名称类型默认值说明
左侧时间日期—The date and time to test.
右侧时间日期—The date and time to compare against.

返回

结果真否

备注

Only the tick values are compared and DateTime.Kind is ignored.

重载 2/4

签名
小于(左侧: DateOnly, 右侧: DateOnly) -> 真否
bool LessThan(DateOnly left, DateOnly right)

检查一个日期是否在另一个之前。

参数

名称类型默认值说明
左侧DateOnly—The date to test.
右侧DateOnly—The date to compare against.

返回

结果真否

重载 3/4

签名
小于(左侧: TimeOnly, 右侧: TimeOnly) -> 真否
bool LessThan(TimeOnly left, TimeOnly right)

检查一个时刻是否早于另一个,从午夜算起,不绕回。

参数

名称类型默认值说明
左侧TimeOnly—The time of day to test.
右侧TimeOnly—The time of day to compare against.

返回

结果真否

重载 4/4

签名
小于(左侧: TimeSpan, 右侧: TimeSpan) -> 真否
bool LessThan(TimeSpan left, TimeSpan right)

检查一个时间间隔是否比另一个短;负的时间间隔视为比零还短。

参数

名称类型默认值说明
左侧TimeSpan—The duration to test.
右侧TimeSpan—The duration to compare against.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

小于或等于

函数

重载 1/4

签名
小于或等于(左侧: 时间日期, 右侧: 时间日期) -> 真否
bool LessThanOrEqual(DateTime left, DateTime right)

检查一个时间日期是否早于或等于另一个。

参数

名称类型默认值说明
左侧时间日期—The date and time to test.
右侧时间日期—The date and time to compare against.

返回

结果真否

备注

Only the tick values are compared and DateTime.Kind is ignored.

重载 2/4

签名
小于或等于(左侧: DateOnly, 右侧: DateOnly) -> 真否
bool LessThanOrEqual(DateOnly left, DateOnly right)

检查一个日期是否在另一个之前或与其是同一天。

参数

名称类型默认值说明
左侧DateOnly—The date to test.
右侧DateOnly—The date to compare against.

返回

结果真否

重载 3/4

签名
小于或等于(左侧: TimeOnly, 右侧: TimeOnly) -> 真否
bool LessThanOrEqual(TimeOnly left, TimeOnly right)

检查一个时刻是否早于或等于另一个,从午夜算起,不绕回。

参数

名称类型默认值说明
左侧TimeOnly—The time of day to test.
右侧TimeOnly—The time of day to compare against.

返回

结果真否

重载 4/4

签名
小于或等于(左侧: TimeSpan, 右侧: TimeSpan) -> 真否
bool LessThanOrEqual(TimeSpan left, TimeSpan right)

检查一个时间间隔是否短于或等于另一个;负的时间间隔视为比零还短。

参数

名称类型默认值说明
左侧TimeSpan—The duration to test.
右侧TimeSpan—The duration to compare against.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

微秒

函数

重载 1/2

签名
微秒(值: 时间日期) -> 整数
int Microsecond(DateTime value)

获取时间日期的微秒部分。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
微秒(值: TimeOnly) -> 整数
int Microsecond(TimeOnly value)

获取时刻的微秒部分。

参数

名称类型默认值说明
值TimeOnly—The time of day.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

微秒数

函数

获取时间间隔的微秒部分,即去掉整毫秒后剩下的部分;要得到整个时间间隔折合的微秒数,请用“总微秒数”。

签名
微秒数(值: TimeSpan) -> 整数
int Microseconds(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

毫秒

函数

重载 1/2

签名
毫秒(值: 时间日期) -> 整数
int Millisecond(DateTime value)

获取时间日期的毫秒部分。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
毫秒(值: TimeOnly) -> 整数
int Millisecond(TimeOnly value)

获取时刻的毫秒部分。

参数

名称类型默认值说明
值TimeOnly—The time of day.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

毫秒数

函数

获取时间间隔的毫秒部分,即去掉整秒后剩下的部分;要得到整个时间间隔折合的毫秒数,请用“总毫秒数”。

签名
毫秒数(值: TimeSpan) -> 整数
int Milliseconds(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

分

函数

重载 1/2

签名
分(值: 时间日期) -> 整数
int Minute(DateTime value)

获取时间日期的分钟。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
分(值: TimeOnly) -> 整数
int Minute(TimeOnly value)

获取时刻的分钟。

参数

名称类型默认值说明
值TimeOnly—The time of day.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

分钟数

函数

获取时间间隔的分钟部分,即去掉整小时后剩下的部分;要得到整个时间间隔折合的分钟数,请用“总分钟数”。

签名
分钟数(值: TimeSpan) -> 整数
int Minutes(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

月

函数

重载 1/2

签名
月(值: 时间日期) -> 整数
int Month(DateTime value)

获取时间日期的月份。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
月(值: DateOnly) -> 整数
int Month(DateOnly value)

获取日期的月份。

参数

名称类型默认值说明
值DateOnly—The date.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

乘以

函数

把时间间隔乘以一个倍数,例如求它的三倍或一半。

签名
乘以(值: TimeSpan, 系数: 数字) -> TimeSpan
TimeSpan Multiply(TimeSpan value, double factor)

参数

名称类型默认值说明
值TimeSpan—The duration to scale.
系数数字—The multiplier, which may be fractional or negative; NaN throws an System.ArgumentException.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

纳秒

函数

重载 1/2

签名
纳秒(值: 时间日期) -> 整数
int Nanosecond(DateTime value)

获取时间日期的纳秒部分。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
纳秒(值: TimeOnly) -> 整数
int Nanosecond(TimeOnly value)

获取时刻的纳秒部分。

参数

名称类型默认值说明
值TimeOnly—The time of day.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

纳秒数

函数

获取时间间隔的纳秒部分,即去掉整微秒后剩下的部分。

签名
纳秒数(值: TimeSpan) -> 整数
int Nanoseconds(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

取反

函数

取时间间隔的相反数:5 分钟变成 -5 分钟,反之亦然。

签名
取反(值: TimeSpan) -> TimeSpan
TimeSpan Negate(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration to negate; TimeSpan.MinValue throws an System.OverflowException because its negation does not fit.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

不相等

函数

重载 1/4

签名
不相等(左侧: 时间日期, 右侧: 时间日期) -> 真否
bool NotEquals(DateTime left, DateTime right)

检查两个时间日期是否不同。

参数

名称类型默认值说明
左侧时间日期—The first date and time.
右侧时间日期—The second date and time.

返回

结果真否

备注

Only the tick values are compared and DateTime.Kind is ignored.

重载 2/4

签名
不相等(左侧: DateOnly, 右侧: DateOnly) -> 真否
bool NotEquals(DateOnly left, DateOnly right)

检查两个日期是否不是同一天。

参数

名称类型默认值说明
左侧DateOnly—The first date.
右侧DateOnly—The second date.

返回

结果真否

重载 3/4

签名
不相等(左侧: TimeOnly, 右侧: TimeOnly) -> 真否
bool NotEquals(TimeOnly left, TimeOnly right)

检查两个时刻是否不同。

参数

名称类型默认值说明
左侧TimeOnly—The first time of day.
右侧TimeOnly—The second time of day.

返回

结果真否

重载 4/4

签名
不相等(左侧: TimeSpan, 右侧: TimeSpan) -> 真否
bool NotEquals(TimeSpan left, TimeSpan right)

检查两个时间间隔的长度是否不同。

参数

名称类型默认值说明
左侧TimeSpan—The first duration.
右侧TimeSpan—The second duration.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

解析时间日期

函数

重载 1/3

签名
解析时间日期(文本: 文本) -> 时间日期
DateTime Parse(string s)

把文本解析为时间日期。

参数

名称类型默认值说明
文本文本—

返回

结果时间日期

重载 2/3

签名
解析时间日期(文本: 文本, 提供者: IFormatProvider) -> 时间日期
DateTime Parse(string s, IFormatProvider provider)

按给定区域的写法从文本中读取时间日期。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that is not a date and time throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果时间日期

重载 3/3

签名
解析时间日期 -> 时间日期
    文本: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
DateTime Parse(
    string s,
    IFormatProvider provider,
    DateTimeStyles styles)

按给定区域的写法从文本中读取时间日期,可设置如何处理空白和时区。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that is not a date and time throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—Options such as DateTimeStyles.AdjustToUniversal or DateTimeStyles.AssumeUniversal; a contradictory combination throws an System.ArgumentException.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

解析日期

函数

重载 1/3

签名
解析日期(文本: 文本) -> DateOnly
DateOnly ParseDateOnly(string s)

把文本解析为日期。

参数

名称类型默认值说明
文本文本—

返回

结果DateOnly

重载 2/3

签名
解析日期(文本: 文本, 提供者: IFormatProvider) -> DateOnly
DateOnly ParseDateOnly(string s, IFormatProvider provider)

按给定区域的写法从文本中读取日期;文本中不能含有时刻。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that is not a date, or that includes a time, throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果DateOnly

重载 3/3

签名
解析日期 -> DateOnly
    文本: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
DateOnly ParseDateOnly(
    string s,
    IFormatProvider provider,
    DateTimeStyles styles)

按给定区域的写法从文本中读取日期,可设置如何处理空白。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that is not a date, or that includes a time, throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style throws an System.ArgumentException.

返回

结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

按格式解析时间日期

函数

重载 1/3

签名
按格式解析时间日期 -> 时间日期
    文本: 文本
    格式: 文本
    提供者: IFormatProvider
DateTime ParseExact(
    string s,
    string format,
    IFormatProvider provider)

从必须完全符合某一格式(如 "yyyy-MM-dd HH:mm:ss")的文本中读取时间日期。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that does not match the format throws a System.FormatException.
格式文本—The standard or custom format the text must match.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果时间日期

重载 2/3

签名
按格式解析时间日期 -> 时间日期
    文本: 文本
    格式: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
DateTime ParseExact(
    string s,
    string format,
    IFormatProvider provider,
    DateTimeStyles styles)

从必须完全符合某一格式的文本中读取时间日期,可设置如何处理空白和时区。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that does not match the format throws a System.FormatException.
格式文本—The standard or custom format the text must match.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—Options such as DateTimeStyles.AllowWhiteSpaces or DateTimeStyles.AssumeUniversal; a contradictory combination throws an System.ArgumentException.

返回

结果时间日期

重载 3/3

签名
按格式解析时间日期 -> 时间日期
    文本: 文本
    格式: 文本数组
    提供者: IFormatProvider
    样式: DateTimeStyles
DateTime ParseExact(
    string s,
    string[] formats,
    IFormatProvider provider,
    DateTimeStyles styles)

从必须完全符合若干格式之一的文本中读取时间日期,适用于输入有多种排布的情况。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that matches none of the formats throws a System.FormatException.
格式文本数组—The formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—Options such as DateTimeStyles.AllowWhiteSpaces or DateTimeStyles.AssumeUniversal; a contradictory combination throws an System.ArgumentException.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

按格式解析日期

函数

重载 1/3

签名
按格式解析日期 -> DateOnly
    文本: 文本
    格式: 文本
    提供者: IFormatProvider
DateOnly ParseExactDateOnly(
    string s,
    string format,
    IFormatProvider provider)

从必须完全符合某一格式(如 "yyyy-MM-dd")的文本中读取日期。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that does not match the format throws a System.FormatException.
格式文本—The standard or custom date format the text must match.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果DateOnly

重载 2/3

签名
按格式解析日期 -> DateOnly
    文本: 文本
    格式: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
DateOnly ParseExactDateOnly(
    string s,
    string format,
    IFormatProvider provider,
    DateTimeStyles styles)

从必须完全符合某一格式的文本中读取日期,可设置如何处理空白。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that does not match the format throws a System.FormatException.
格式文本—The standard or custom date format the text must match.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style throws an System.ArgumentException.

返回

结果DateOnly

重载 3/3

签名
按格式解析日期 -> DateOnly
    文本: 文本
    格式: 文本数组
    提供者: IFormatProvider
    样式: DateTimeStyles
DateOnly ParseExactDateOnly(
    string s,
    string[] formats,
    IFormatProvider provider,
    DateTimeStyles styles)

从必须完全符合若干格式之一的文本中读取日期,适用于输入有多种排布的情况。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that matches none of the formats throws a System.FormatException.
格式文本数组—The date formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style throws an System.ArgumentException.

返回

结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

按格式解析时刻

函数

重载 1/3

签名
按格式解析时刻 -> TimeOnly
    文本: 文本
    格式: 文本
    提供者: IFormatProvider
TimeOnly ParseExactTimeOnly(
    string s,
    string format,
    IFormatProvider provider)

从必须完全符合某一格式(如 "HH:mm:ss")的文本中读取时刻。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that does not match the format throws a System.FormatException.
格式文本—The standard or custom time format the text must match.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果TimeOnly

重载 2/3

签名
按格式解析时刻 -> TimeOnly
    文本: 文本
    格式: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
TimeOnly ParseExactTimeOnly(
    string s,
    string format,
    IFormatProvider provider,
    DateTimeStyles styles)

从必须完全符合某一格式的文本中读取时刻,可设置如何处理空白。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that does not match the format throws a System.FormatException.
格式文本—The standard or custom time format the text must match.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style throws an System.ArgumentException.

返回

结果TimeOnly

重载 3/3

签名
按格式解析时刻 -> TimeOnly
    文本: 文本
    格式: 文本数组
    提供者: IFormatProvider
    样式: DateTimeStyles
TimeOnly ParseExactTimeOnly(
    string s,
    string[] formats,
    IFormatProvider provider,
    DateTimeStyles styles)

从必须完全符合若干格式之一的文本中读取时刻,适用于输入有多种排布的情况。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that matches none of the formats throws a System.FormatException.
格式文本数组—The time formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style throws an System.ArgumentException.

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

按格式解析时间间隔

函数

重载 1/4

签名
按格式解析时间间隔 -> TimeSpan
    输入: 文本
    格式: 文本
    提供者: IFormatProvider
TimeSpan ParseExactTimeSpan(
    string input,
    string format,
    IFormatProvider provider)

从必须完全符合某一格式(如 "c" 或 @"hh\:mm" 这样的自定义格式)的文本中读取时间间隔。

参数

名称类型默认值说明
输入文本—The text to read; null throws an System.ArgumentNullException, text that does not match throws a System.FormatException, and a value beyond the System.TimeSpan range throws an System.OverflowException.
格式文本—The standard or custom format the text must match.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果TimeSpan

重载 2/4

签名
按格式解析时间间隔 -> TimeSpan
    输入: 文本
    格式: 文本
    提供者: IFormatProvider
    样式: TimeSpanStyles
TimeSpan ParseExactTimeSpan(
    string input,
    string format,
    IFormatProvider provider,
    TimeSpanStyles styles)

从必须完全符合某一格式的文本中读取时间间隔,可选择将其视为负值。

参数

名称类型默认值说明
输入文本—The text to read; null throws an System.ArgumentNullException, text that does not match throws a System.FormatException, and a value beyond the System.TimeSpan range throws an System.OverflowException.
格式文本—The standard or custom format the text must match.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式TimeSpanStyles—TimeSpanStyles.AssumeNegative makes a custom-format result negative; TimeSpanStyles.None leaves it as written.

返回

结果TimeSpan

重载 3/4

签名
按格式解析时间间隔 -> TimeSpan
    输入: 文本
    格式: 文本数组
    提供者: IFormatProvider
TimeSpan ParseExactTimeSpan(
    string input,
    string[] formats,
    IFormatProvider provider)

从必须完全符合若干格式之一的文本中读取时间间隔,适用于输入有多种排布的情况。

参数

名称类型默认值说明
输入文本—The text to read; null throws an System.ArgumentNullException, text that matches none of the formats throws a System.FormatException, and a value beyond the System.TimeSpan range throws an System.OverflowException.
格式文本数组—The formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果TimeSpan

重载 4/4

签名
按格式解析时间间隔 -> TimeSpan
    输入: 文本
    格式: 文本数组
    提供者: IFormatProvider
    样式: TimeSpanStyles
TimeSpan ParseExactTimeSpan(
    string input,
    string[] formats,
    IFormatProvider provider,
    TimeSpanStyles styles)

从必须完全符合若干格式之一的文本中读取时间间隔,可选择将其视为负值。

参数

名称类型默认值说明
输入文本—The text to read; null throws an System.ArgumentNullException, text that matches none of the formats throws a System.FormatException, and a value beyond the System.TimeSpan range throws an System.OverflowException.
格式文本数组—The formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式TimeSpanStyles—TimeSpanStyles.AssumeNegative makes a custom-format result negative; TimeSpanStyles.None leaves it as written.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

解析时刻

函数

重载 1/3

签名
解析时刻(文本: 文本) -> TimeOnly
TimeOnly ParseTimeOnly(string s)

把文本解析为时刻。

参数

名称类型默认值说明
文本文本—

返回

结果TimeOnly

重载 2/3

签名
解析时刻(文本: 文本, 提供者: IFormatProvider) -> TimeOnly
TimeOnly ParseTimeOnly(string s, IFormatProvider provider)

按给定区域的写法从文本中读取时刻;文本中不能含有日期。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that is not a time, or that includes a date, throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果TimeOnly

重载 3/3

签名
解析时刻 -> TimeOnly
    文本: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
TimeOnly ParseTimeOnly(
    string s,
    IFormatProvider provider,
    DateTimeStyles styles)

按给定区域的写法从文本中读取时刻,可设置如何处理空白。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException and text that is not a time, or that includes a date, throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style throws an System.ArgumentException.

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

解析时间间隔

函数

重载 1/2

签名
解析时间间隔(文本: 文本) -> TimeSpan
TimeSpan ParseTimeSpan(string s)

把文本解析为时间间隔。

参数

名称类型默认值说明
文本文本—

返回

结果TimeSpan

重载 2/2

签名
解析时间间隔(文本: 文本, 提供者: IFormatProvider) -> TimeSpan
TimeSpan ParseTimeSpan(string s, IFormatProvider provider)

从形如 [-][d.]hh:mm[:ss[.fffffff]] 的文本中读取时间间隔,例如 "1.02:30:00" 表示一天两个半小时,小数点按给定区域的写法。

参数

名称类型默认值说明
文本文本—The text to read; null throws an System.ArgumentNullException, text in the wrong form throws a System.FormatException, and a part out of range (such as 24 hours) or a total beyond the System.TimeSpan range throws an System.OverflowException.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

秒

函数

重载 1/2

签名
秒(值: 时间日期) -> 整数
int Second(DateTime value)

获取时间日期的秒。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
秒(值: TimeOnly) -> 整数
int Second(TimeOnly value)

获取时刻的秒。

参数

名称类型默认值说明
值TimeOnly—The time of day.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

秒数

函数

获取时间间隔的秒部分,即去掉整分钟后剩下的部分;要得到整个时间间隔折合的秒数,请用“总秒数”。

签名
秒数(值: TimeSpan) -> 整数
int Seconds(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

指定时间种类

函数

创建一个计时周期与给定值相同、但时间类型为指定类型的新时间日期。

签名
指定时间种类(值: 时间日期, 种类: DateTimeKind) -> 时间日期
DateTime SpecifyKind(DateTime value, DateTimeKind kind)

参数

名称类型默认值说明
值时间日期—
种类DateTimeKind—

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

减去

函数

重载 1/4

签名
减去(左侧: 时间日期, 右侧: 时间日期) -> TimeSpan
TimeSpan Subtract(DateTime left, DateTime right)

计算从一个时间日期到另一个经过的时间。

参数

名称类型默认值说明
左侧时间日期—The later date and time.
右侧时间日期—The earlier date and time.

返回

结果TimeSpan

备注

The tick values are subtracted directly and DateTime.Kind is ignored, so convert both values to UTC first if one is local and the other UTC.

重载 2/4

签名
减去(值: 时间日期, 增量: TimeSpan) -> 时间日期
DateTime Subtract(DateTime value, TimeSpan delta)

把时间日期提前一段时间间隔。

参数

名称类型默认值说明
值时间日期—The starting date and time; its kind is kept.
增量TimeSpan—The duration to subtract; a negative duration moves forward.

返回

结果时间日期

重载 3/4

签名
减去(左侧: TimeOnly, 右侧: TimeOnly) -> TimeSpan
TimeSpan Subtract(TimeOnly left, TimeOnly right)

计算钟表从一个时刻向前走到另一个时刻需要多久,必要时越过午夜。

参数

名称类型默认值说明
左侧TimeOnly—The time of day to reach.
右侧TimeOnly—The time of day to start from.

返回

结果TimeSpan

备注

The result is never negative: from 23:00 to 01:00 is 2 hours, not -22 hours.

重载 4/4

签名
减去(左侧: TimeSpan, 右侧: TimeSpan) -> TimeSpan
TimeSpan Subtract(TimeSpan left, TimeSpan right)

从一个时间间隔中减去另一个。

参数

名称类型默认值说明
左侧TimeSpan—The duration to subtract from.
右侧TimeSpan—The duration to subtract.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

计时周期数

函数

重载 1/3

签名
计时周期数(值: 时间日期) -> 大整数
long Ticks(DateTime value)

把时间日期表示为一个计时周期数,便于存储或做精确运算。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果大整数

重载 2/3

签名
计时周期数(值: TimeOnly) -> 大整数
long Ticks(TimeOnly value)

把时刻表示为自午夜起的计时周期数。

参数

名称类型默认值说明
值TimeOnly—The time of day.

返回

结果大整数

重载 3/3

签名
计时周期数(值: TimeSpan) -> 大整数
long Ticks(TimeSpan value)

把时间间隔表示为一个计时周期数,便于存储或做精确运算。

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

相隔时间

函数

计算从一个日期到另一个日期的时间,结果是以整天计的时间间隔。

签名
相隔时间(左侧: DateOnly, 右侧: DateOnly) -> TimeSpan
TimeSpan TimeBetween(DateOnly left, DateOnly right)

参数

名称类型默认值说明
左侧DateOnly—The later date.
右侧DateOnly—The earlier date.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

一天中的时刻

函数

获取时间日期的时刻,表示为自午夜起的时间间隔。

签名
一天中的时刻(值: 时间日期) -> TimeSpan
TimeSpan TimeOfDay(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从时间日期取时刻

函数

取时间日期的时刻,去掉其日期。

签名
从时间日期取时刻(值: 时间日期) -> TimeOnly
TimeOnly TimeOnlyFromDateTime(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time to take the time of day from; its kind is ignored and no time-zone conversion is made.

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从计时周期数取时刻

函数

用自午夜起的计时周期数创建时刻。

签名
从计时周期数取时刻(计时周期数: 大整数) -> TimeOnly
TimeOnly TimeOnlyFromTicks(long ticks)

参数

名称类型默认值说明
计时周期数大整数—The number of 100-nanosecond ticks since midnight, from 0 to one less than TimeSpan.TicksPerDay; any other value throws an System.ArgumentOutOfRangeException.

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

从时间间隔取时刻

函数

把自午夜起的时间间隔转换为时刻,例如把 13 小时转换为 13:00。

签名
从时间间隔取时刻(值: TimeSpan) -> TimeOnly
TimeOnly TimeOnlyFromTimeSpan(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The time elapsed since midnight; must be at least zero and less than one day, otherwise an System.ArgumentOutOfRangeException is thrown.

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

由天数生成时间间隔

函数

用天数创建时间间隔,天数可以是小数或负数(1.5 即一天半)。

签名
由天数生成时间间隔(天数: 数字) -> TimeSpan
TimeSpan TimeSpanFromDays(double days)

参数

名称类型默认值说明
天数数字—The number of days; NaN throws an System.ArgumentException and a value beyond the System.TimeSpan range throws an System.OverflowException.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

由小时数生成时间间隔

函数

用小时数创建时间间隔,可以是小数或负数。

签名
由小时数生成时间间隔(小时数: 数字) -> TimeSpan
TimeSpan TimeSpanFromHours(double hours)

参数

名称类型默认值说明
小时数数字—The number of hours; NaN throws an System.ArgumentException and a value beyond the System.TimeSpan range throws an System.OverflowException.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

由微秒数生成时间间隔

函数

用微秒数创建时间间隔,可以是小数或负数。

签名
由微秒数生成时间间隔(微秒数: 数字) -> TimeSpan
TimeSpan TimeSpanFromMicroseconds(double microseconds)

参数

名称类型默认值说明
微秒数数字—The number of microseconds; NaN throws an System.ArgumentException and a value beyond the System.TimeSpan range throws an System.OverflowException.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

由毫秒数生成时间间隔

函数

用毫秒数创建时间间隔,可以是小数或负数。

签名
由毫秒数生成时间间隔(毫秒数: 数字) -> TimeSpan
TimeSpan TimeSpanFromMilliseconds(double milliseconds)

参数

名称类型默认值说明
毫秒数数字—The number of milliseconds; NaN throws an System.ArgumentException and a value beyond the System.TimeSpan range throws an System.OverflowException.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

由分钟数生成时间间隔

函数

用分钟数创建时间间隔,可以是小数或负数。

签名
由分钟数生成时间间隔(分钟数: 数字) -> TimeSpan
TimeSpan TimeSpanFromMinutes(double minutes)

参数

名称类型默认值说明
分钟数数字—The number of minutes; NaN throws an System.ArgumentException and a value beyond the System.TimeSpan range throws an System.OverflowException.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

由秒数生成时间间隔

函数

用秒数创建时间间隔,可以是小数或负数。

签名
由秒数生成时间间隔(秒数: 数字) -> TimeSpan
TimeSpan TimeSpanFromSeconds(double seconds)

参数

名称类型默认值说明
秒数数字—The number of seconds; NaN throws an System.ArgumentException and a value beyond the System.TimeSpan range throws an System.OverflowException.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

由计时周期数生成时间间隔

函数

用计时周期数创建时间间隔,一个计时周期为 100 纳秒。

签名
由计时周期数生成时间间隔(计时周期数: 大整数) -> TimeSpan
TimeSpan TimeSpanFromTicks(long ticks)

参数

名称类型默认值说明
计时周期数大整数—The number of ticks; may be negative.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

时间间隔转为时刻

函数

把自午夜起的时间间隔转换为时刻,例如把 13 小时转换为 13:00。

签名
时间间隔转为时刻(值: TimeSpan) -> TimeOnly
TimeOnly TimeSpanToTimeOnly(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The time elapsed since midnight; must be at least zero and less than one day, otherwise an System.ArgumentOutOfRangeException is thrown.

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为二进制值

函数

把时间日期连同其时间类型打包成一个 64 位数字以便存储;“从二进制值还原”可把它还原。

签名
转为二进制值(值: 时间日期) -> 大整数
long ToBinary(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time to pack.

返回

结果大整数

备注

A local value is stored as its UTC instant, so restoring it on a machine in another time zone gives the same moment in that machine's local time.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为日期

函数

取时间日期的日历日期,去掉其时刻。

签名
转为日期(值: 时间日期) -> DateOnly
DateOnly ToDateOnly(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time to take the date from; its kind is ignored and no time-zone conversion is made.

返回

结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为时间日期

函数

重载 1/2

签名
转为时间日期(日期: DateOnly, 时间: TimeOnly) -> 时间日期
DateTime ToDateTime(DateOnly date, TimeOnly time)

把一个日期和一个时刻合成一个时间日期。

参数

名称类型默认值说明
日期DateOnly—The calendar date.
时间TimeOnly—The time of day on that date.

返回

结果时间日期

重载 2/2

签名
转为时间日期 -> 时间日期
    日期: DateOnly
    时间: TimeOnly
    种类: DateTimeKind
DateTime ToDateTime(
    DateOnly date,
    TimeOnly time,
    DateTimeKind kind)

把一个日期和一个时刻合成一个时间日期,并标为本地时间、UTC 或未指定。

参数

名称类型默认值说明
日期DateOnly—The calendar date.
时间TimeOnly—The time of day on that date.
种类DateTimeKind—Whether the result is local time, UTC or unspecified.

返回

结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为文件时间

函数

把时间日期转换为 Windows 文件时间:自 1601-01-01 00:00:00 UTC 起经过的 100 纳秒间隔数。

签名
转为文件时间(值: 时间日期) -> 大整数
long ToFileTime(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time; a local or unspecified value is treated as local time and converted to UTC first.

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为 UTC 文件时间

函数

把时间日期转换为 Windows 文件时间,未指定类型的值视为已是 UTC。

签名
转为 UTC 文件时间(值: 时间日期) -> 大整数
long ToFileTimeUtc(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time; only a local value is converted to UTC first, while UTC and unspecified values are used as they are.

返回

结果大整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为本地时间

函数

把时间日期转换为本地时间。

签名
转为本地时间(值: 时间日期) -> 时间日期
DateTime ToLocalTime(DateTime value)

参数

名称类型默认值说明
值时间日期—

返回

结果时间日期

备注

DateTime.ToLocalTime uses the DateTime.Kind value:
DateTimeKind.Utc is converted to local time, DateTimeKind.Local
is returned unchanged, and DateTimeKind.Unspecified is assumed to be UTC before conversion.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为长日期文本

函数

重载 1/2

签名
转为长日期文本(值: 时间日期) -> 文本
string ToLongDateString(DateTime value)

按当前区域的长日期模式写出时间日期中的日期,例如美式英语中的 Saturday, June 15, 2024。

参数

名称类型默认值说明
值时间日期—The date and time; its time of day is not shown.

返回

结果文本

重载 2/2

签名
转为长日期文本(值: DateOnly) -> 文本
string ToLongDateString(DateOnly value)

按当前区域的长日期模式写出日期,例如美式英语中的 Saturday, June 15, 2024。

参数

名称类型默认值说明
值DateOnly—The date to format.

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为长时间文本

函数

重载 1/2

签名
转为长时间文本(值: 时间日期) -> 文本
string ToLongTimeString(DateTime value)

按当前区域的长时间模式写出时间日期中的时间,通常包含时、分、秒。

参数

名称类型默认值说明
值时间日期—The date and time; its date is not shown.

返回

结果文本

重载 2/2

签名
转为长时间文本(值: TimeOnly) -> 文本
string ToLongTimeString(TimeOnly value)

按当前区域的长时间模式写出时刻,通常包含时、分、秒。

参数

名称类型默认值说明
值TimeOnly—The time of day to format.

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为 OLE 自动化日期

函数

把时间日期转换为 OLE 自动化日期,即 Excel 等 Office 应用表示日期所用的数字格式。

签名
转为 OLE 自动化日期(值: 时间日期) -> 数字
double ToOADate(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time; DateTime.MinValue gives 0, and other dates before year 100 throw an System.OverflowException.

返回

结果数字

备注

The whole part counts days from 1899-12-30 and the fraction is the time of day, so 1.5 is 1899-12-31 12:00. The kind is ignored.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为短日期文本

函数

重载 1/2

签名
转为短日期文本(值: 时间日期) -> 文本
string ToShortDateString(DateTime value)

按当前区域的短日期模式写出时间日期中的日期,例如美式英语中的 6/15/2024。

参数

名称类型默认值说明
值时间日期—The date and time; its time of day is not shown.

返回

结果文本

重载 2/2

签名
转为短日期文本(值: DateOnly) -> 文本
string ToShortDateString(DateOnly value)

按当前区域的短日期模式写出日期,例如美式英语中的 6/15/2024。

参数

名称类型默认值说明
值DateOnly—The date to format.

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为短时间文本

函数

重载 1/2

签名
转为短时间文本(值: 时间日期) -> 文本
string ToShortTimeString(DateTime value)

按当前区域的短时间模式写出时间日期中的时间,通常包含时和分。

参数

名称类型默认值说明
值时间日期—The date and time; its date is not shown.

返回

结果文本

重载 2/2

签名
转为短时间文本(值: TimeOnly) -> 文本
string ToShortTimeString(TimeOnly value)

按当前区域的短时间模式写出时刻,通常包含时和分。

参数

名称类型默认值说明
值TimeOnly—The time of day to format.

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为文本

函数

重载 1/15

签名
转为文本(值: 时间日期) -> 文本
string ToString(DateTime value)

把时间日期转换为文本。

参数

名称类型默认值说明
值时间日期—

返回

结果文本

重载 2/15

签名
转为文本(值: 时间日期, 格式: 文本) -> 文本
string ToString(DateTime value, string format)

用某一格式把时间日期写成文本(不随机器的区域改变),格式如 "yyyy-MM-dd HH:mm",或标准格式说明符,如表示可往返 ISO 8601 的 "o"。

参数

名称类型默认值说明
值时间日期—The date and time to format.
格式文本—A standard or custom date and time format string; null or empty uses the general "G" format, and an invalid one throws a System.FormatException.

返回

结果文本

重载 3/15

签名
转为文本(值: 时间日期, 提供者: IFormatProvider) -> 文本
string ToString(DateTime value, IFormatProvider provider)

按给定区域的常规“G”格式把时间日期写成文本。

参数

名称类型默认值说明
值时间日期—The date and time to format.
提供者IFormatProvider—The culture whose conventions to use, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果文本

重载 4/15

签名
转为文本 -> 文本
    值: 时间日期
    格式: 文本
    提供者: IFormatProvider
string ToString(
    DateTime value,
    string format,
    IFormatProvider provider)

按某一格式和给定区域的习惯把时间日期写成文本。

参数

名称类型默认值说明
值时间日期—The date and time to format.
格式文本—A standard or custom date and time format string; null or empty uses the general "G" format, and an invalid one throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to use, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果文本

重载 5/15

签名
转为文本(值: DateOnly) -> 文本
string ToString(DateOnly value)

把日期转换为文本。

参数

名称类型默认值说明
值DateOnly—

返回

结果文本

重载 6/15

签名
转为文本(值: DateOnly, 格式: 文本) -> 文本
string ToString(DateOnly value, string format)

用某一格式把日期写成文本(不随机器的区域改变),格式如 "yyyy-MM-dd",或表示 ISO 8601 的 "o"。

参数

名称类型默认值说明
值DateOnly—The date to format.
格式文本—A standard or custom date format string; null or empty uses the short date "d" format, and an invalid one or one that asks for a time part throws a System.FormatException.

返回

结果文本

重载 7/15

签名
转为文本(值: DateOnly, 提供者: IFormatProvider) -> 文本
string ToString(DateOnly value, IFormatProvider provider)

按给定区域的短日期模式把日期写成文本。

参数

名称类型默认值说明
值DateOnly—The date to format.
提供者IFormatProvider—The culture whose conventions to use, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果文本

重载 8/15

签名
转为文本 -> 文本
    值: DateOnly
    格式: 文本
    提供者: IFormatProvider
string ToString(
    DateOnly value,
    string format,
    IFormatProvider provider)

按某一格式和给定区域的习惯把日期写成文本。

参数

名称类型默认值说明
值DateOnly—The date to format.
格式文本—A standard or custom date format string; null or empty uses the short date "d" format, and an invalid one or one that asks for a time part throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to use, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果文本

重载 9/15

签名
转为文本(值: TimeOnly) -> 文本
string ToString(TimeOnly value)

把时刻转换为文本。

参数

名称类型默认值说明
值TimeOnly—

返回

结果文本

重载 10/15

签名
转为文本(值: TimeOnly, 格式: 文本) -> 文本
string ToString(TimeOnly value, string format)

用某一格式把时刻写成文本(不随机器的区域改变),格式如 "HH:mm:ss",或表示 ISO 8601 的 "o"。

参数

名称类型默认值说明
值TimeOnly—The time of day to format.
格式文本—A standard or custom time format string; null or empty uses the short time "t" format, and an invalid one or one that asks for a date part throws a System.FormatException.

返回

结果文本

重载 11/15

签名
转为文本(值: TimeOnly, 提供者: IFormatProvider) -> 文本
string ToString(TimeOnly value, IFormatProvider provider)

按给定区域的短时间模式把时刻写成文本。

参数

名称类型默认值说明
值TimeOnly—The time of day to format.
提供者IFormatProvider—The culture whose conventions to use, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果文本

重载 12/15

签名
转为文本 -> 文本
    值: TimeOnly
    格式: 文本
    提供者: IFormatProvider
string ToString(
    TimeOnly value,
    string format,
    IFormatProvider provider)

按某一格式和给定区域的习惯把时刻写成文本。

参数

名称类型默认值说明
值TimeOnly—The time of day to format.
格式文本—A standard or custom time format string; null or empty uses the short time "t" format, and an invalid one or one that asks for a date part throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to use, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果文本

重载 13/15

签名
转为文本(值: TimeSpan) -> 文本
string ToString(TimeSpan value)

把时间间隔转换为文本。

参数

名称类型默认值说明
值TimeSpan—

返回

结果文本

重载 14/15

签名
转为文本(值: TimeSpan, 格式: 文本) -> 文本
string ToString(TimeSpan value, string format)

用某一格式把时间间隔写成文本:"c" 表示固定的 [-][d.]hh:mm:ss[.fffffff] 形式,"g" 或 "G" 表示随区域变化的短形式或长形式,也可以是 @"hh\:mm" 这样的自定义格式。

参数

名称类型默认值说明
值TimeSpan—The duration to format.
格式文本—The format string; null or empty uses "c", and an invalid one throws a System.FormatException.

返回

结果文本

重载 15/15

签名
转为文本 -> 文本
    值: TimeSpan
    格式: 文本
    提供者: IFormatProvider
string ToString(
    TimeSpan value,
    string format,
    IFormatProvider provider)

按某一格式和给定区域的习惯把时间间隔写成文本,区域会影响 "g" 和 "G" 格式。

参数

名称类型默认值说明
值TimeSpan—The duration to format.
格式文本—The format string, such as "c", "g", "G" or a custom pattern; null or empty uses "c", and an invalid one throws a System.FormatException.
提供者IFormatProvider—The culture whose conventions to use, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

总天数

函数

获取时间间隔折合的天数,含小数部分(36 小时即 1.5)。

签名
总天数(值: TimeSpan) -> 数字
double TotalDays(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果数字
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

总小时数

函数

获取时间间隔折合的小时数,含小数部分(90 分钟即 1.5)。

签名
总小时数(值: TimeSpan) -> 数字
double TotalHours(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果数字
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

总微秒数

函数

获取时间间隔折合的微秒数,含小数部分。

签名
总微秒数(值: TimeSpan) -> 数字
double TotalMicroseconds(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果数字
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

总毫秒数

函数

获取时间间隔折合的毫秒数,含小数部分。

签名
总毫秒数(值: TimeSpan) -> 数字
double TotalMilliseconds(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果数字
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

总分钟数

函数

获取时间间隔折合的分钟数,含小数部分。

签名
总分钟数(值: TimeSpan) -> 数字
double TotalMinutes(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果数字
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

总纳秒数

函数

获取时间间隔折合的纳秒数。

签名
总纳秒数(值: TimeSpan) -> 数字
double TotalNanoseconds(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果数字
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

总秒数

函数

获取时间间隔折合的秒数,含小数部分。

签名
总秒数(值: TimeSpan) -> 数字
double TotalSeconds(TimeSpan value)

参数

名称类型默认值说明
值TimeSpan—The duration.

返回

结果数字
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为时刻

函数

取时间日期的时刻,去掉其日期。

签名
转为时刻(值: 时间日期) -> TimeOnly
TimeOnly ToTimeOnly(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time to take the time of day from; its kind is ignored and no time-zone conversion is made.

返回

结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为时间间隔

函数

把时刻转换为自午夜起的时间间隔,例如把 13:30 转换为 13 小时 30 分钟。

签名
转为时间间隔(值: TimeOnly) -> TimeSpan
TimeSpan ToTimeSpan(TimeOnly value)

参数

名称类型默认值说明
值TimeOnly—The time of day.

返回

结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为 UTC 时间

函数

把时间日期转换为协调世界时(UTC)。

签名
转为 UTC 时间(值: 时间日期) -> 时间日期
DateTime ToUniversalTime(DateTime value)

参数

名称类型默认值说明
值时间日期—

返回

结果时间日期

备注

DateTime.ToUniversalTime uses the DateTime.Kind value:
DateTimeKind.Local is converted to UTC, DateTimeKind.Utc
is returned unchanged, and DateTimeKind.Unspecified is assumed to be local time before conversion.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为 Unix 毫秒时间戳

函数

把时间日期转换为毫秒级 Unix 时间戳:自 1970-01-01 00:00:00 UTC 起经过的整毫秒数,JavaScript 和许多 Web API 使用这种形式。

签名
转为 Unix 毫秒时间戳(值: 时间日期) -> 大整数
long ToUnixTimeMilliseconds(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time to convert.

返回

结果大整数

备注

A UTC value is used as it is; a local or unspecified value is treated as local time and converted to UTC using the local time zone. Times before the epoch give negative numbers, and fractions of a millisecond are discarded.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

转为 Unix 秒时间戳

函数

把时间日期转换为 Unix 时间戳:自 1970-01-01 00:00:00 UTC 起经过的整秒数。

签名
转为 Unix 秒时间戳(值: 时间日期) -> 大整数
long ToUnixTimeSeconds(DateTime value)

参数

名称类型默认值说明
值时间日期—The date and time to convert.

返回

结果大整数

备注

A UTC value is used as it is; a local or unspecified value is treated as local time and converted to UTC using the local time zone. Times before the epoch give negative numbers, and fractions of a second are discarded.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

尝试解析时间日期

函数

重载 1/2

签名
尝试解析时间日期(文本: 文本) -> (结果: 真否, 结果: 时间日期)
bool TryParse(string s, out DateTime result)

尝试从文本中读取时间日期(不随机器的区域改变),失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null or unreadable text makes the node report failure.

返回

结果真否
结果时间日期

重载 2/2

签名
尝试解析时间日期 -> (结果: 真否, 结果: 时间日期)
    文本: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
bool TryParse(
    string s,
    IFormatProvider provider,
    DateTimeStyles styles,
    out DateTime result)

尝试按给定区域的写法从文本中读取时间日期,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null or unreadable text makes the node report failure.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—Options such as DateTimeStyles.AdjustToUniversal; a contradictory combination still throws an System.ArgumentException.

返回

结果真否
结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

尝试解析日期

函数

重载 1/2

签名
尝试解析日期(文本: 文本) -> (结果: 真否, 结果: DateOnly)
bool TryParseDateOnly(string s, out DateOnly result)

尝试从文本中读取日期(不随机器的区域改变),失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null, unreadable text or text that includes a time makes the node report failure.

返回

结果真否
结果DateOnly

重载 2/2

签名
尝试解析日期 -> (结果: 真否, 结果: DateOnly)
    文本: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
bool TryParseDateOnly(
    string s,
    IFormatProvider provider,
    DateTimeStyles styles,
    out DateOnly result)

尝试按给定区域的写法从文本中读取日期,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null, unreadable text or text that includes a time makes the node report failure.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style still throws an System.ArgumentException.

返回

结果真否
结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

尝试按格式解析时间日期

函数

重载 1/2

签名
尝试按格式解析时间日期 -> (结果: 真否, 结果: 时间日期)
    文本: 文本
    格式: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
bool TryParseExact(
    string s,
    string format,
    IFormatProvider provider,
    DateTimeStyles styles,
    out DateTime result)

尝试从必须完全符合某一格式的文本中读取时间日期,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null or text that does not match makes the node report failure.
格式文本—The standard or custom format the text must match; null makes the node report failure.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—Options such as DateTimeStyles.AllowWhiteSpaces; a contradictory combination still throws an System.ArgumentException.

返回

结果真否
结果时间日期

重载 2/2

签名
尝试按格式解析时间日期 -> (结果: 真否, 结果: 时间日期)
    文本: 文本
    格式: 文本数组
    提供者: IFormatProvider
    样式: DateTimeStyles
bool TryParseExact(
    string s,
    string[] formats,
    IFormatProvider provider,
    DateTimeStyles styles,
    out DateTime result)

尝试从必须完全符合若干格式之一的文本中读取时间日期,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null or text that matches none of the formats makes the node report failure.
格式文本数组—The formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—Options such as DateTimeStyles.AllowWhiteSpaces; a contradictory combination still throws an System.ArgumentException.

返回

结果真否
结果时间日期
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

尝试按格式解析日期

函数

重载 1/2

签名
尝试按格式解析日期 -> (结果: 真否, 结果: DateOnly)
    文本: 文本
    格式: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
bool TryParseExactDateOnly(
    string s,
    string format,
    IFormatProvider provider,
    DateTimeStyles styles,
    out DateOnly result)

尝试从必须完全符合某一格式的文本中读取日期,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null or text that does not match makes the node report failure.
格式文本—The standard or custom date format the text must match; null makes the node report failure.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style still throws an System.ArgumentException.

返回

结果真否
结果DateOnly

重载 2/2

签名
尝试按格式解析日期 -> (结果: 真否, 结果: DateOnly)
    文本: 文本
    格式: 文本数组
    提供者: IFormatProvider
    样式: DateTimeStyles
bool TryParseExactDateOnly(
    string s,
    string[] formats,
    IFormatProvider provider,
    DateTimeStyles styles,
    out DateOnly result)

尝试从必须完全符合若干格式之一的文本中读取日期,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null or text that matches none of the formats makes the node report failure.
格式文本数组—The date formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style still throws an System.ArgumentException.

返回

结果真否
结果DateOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

尝试按格式解析时刻

函数

重载 1/2

签名
尝试按格式解析时刻 -> (结果: 真否, 结果: TimeOnly)
    文本: 文本
    格式: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
bool TryParseExactTimeOnly(
    string s,
    string format,
    IFormatProvider provider,
    DateTimeStyles styles,
    out TimeOnly result)

尝试从必须完全符合某一格式的文本中读取时刻,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null or text that does not match makes the node report failure.
格式文本—The standard or custom time format the text must match; null makes the node report failure.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style still throws an System.ArgumentException.

返回

结果真否
结果TimeOnly

重载 2/2

签名
尝试按格式解析时刻 -> (结果: 真否, 结果: TimeOnly)
    文本: 文本
    格式: 文本数组
    提供者: IFormatProvider
    样式: DateTimeStyles
bool TryParseExactTimeOnly(
    string s,
    string[] formats,
    IFormatProvider provider,
    DateTimeStyles styles,
    out TimeOnly result)

尝试从必须完全符合若干格式之一的文本中读取时刻,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null or text that matches none of the formats makes the node report failure.
格式文本数组—The time formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style still throws an System.ArgumentException.

返回

结果真否
结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

尝试按格式解析时间间隔

函数

重载 1/4

签名
尝试按格式解析时间间隔 -> (结果: 真否, 结果: TimeSpan)
    输入: 文本
    格式: 文本
    提供者: IFormatProvider
bool TryParseExactTimeSpan(
    string input,
    string format,
    IFormatProvider provider,
    out TimeSpan result)

尝试从必须完全符合某一格式的文本中读取时间间隔,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
输入文本—The text to read; null, text that does not match or a value out of range makes the node report failure.
格式文本—The standard or custom format the text must match; null makes the node report failure.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果真否
结果TimeSpan

重载 2/4

签名
尝试按格式解析时间间隔 -> (结果: 真否, 结果: TimeSpan)
    输入: 文本
    格式: 文本
    提供者: IFormatProvider
    样式: TimeSpanStyles
bool TryParseExactTimeSpan(
    string input,
    string format,
    IFormatProvider provider,
    TimeSpanStyles styles,
    out TimeSpan result)

尝试从必须完全符合某一格式的文本中读取时间间隔,可选择将其视为负值,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
输入文本—The text to read; null, text that does not match or a value out of range makes the node report failure.
格式文本—The standard or custom format the text must match; null makes the node report failure.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式TimeSpanStyles—TimeSpanStyles.AssumeNegative makes a custom-format result negative; TimeSpanStyles.None leaves it as written.

返回

结果真否
结果TimeSpan

重载 3/4

签名
尝试按格式解析时间间隔 -> (结果: 真否, 结果: TimeSpan)
    输入: 文本
    格式: 文本数组
    提供者: IFormatProvider
bool TryParseExactTimeSpan(
    string input,
    string[] formats,
    IFormatProvider provider,
    out TimeSpan result)

尝试从必须完全符合若干格式之一的文本中读取时间间隔,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
输入文本—The text to read; null, text that matches none of the formats or a value out of range makes the node report failure.
格式文本数组—The formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果真否
结果TimeSpan

重载 4/4

签名
尝试按格式解析时间间隔 -> (结果: 真否, 结果: TimeSpan)
    输入: 文本
    格式: 文本数组
    提供者: IFormatProvider
    样式: TimeSpanStyles
bool TryParseExactTimeSpan(
    string input,
    string[] formats,
    IFormatProvider provider,
    TimeSpanStyles styles,
    out TimeSpan result)

尝试从必须完全符合若干格式之一的文本中读取时间间隔,可选择将其视为负值,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
输入文本—The text to read; null, text that matches none of the formats or a value out of range makes the node report failure.
格式文本数组—The formats to try; the first that matches is used.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式TimeSpanStyles—TimeSpanStyles.AssumeNegative makes a custom-format result negative; TimeSpanStyles.None leaves it as written.

返回

结果真否
结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

尝试解析时刻

函数

重载 1/2

签名
尝试解析时刻(文本: 文本) -> (结果: 真否, 结果: TimeOnly)
bool TryParseTimeOnly(string s, out TimeOnly result)

尝试从文本中读取时刻(不随机器的区域改变),失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null, unreadable text or text that includes a date makes the node report failure.

返回

结果真否
结果TimeOnly

重载 2/2

签名
尝试解析时刻 -> (结果: 真否, 结果: TimeOnly)
    文本: 文本
    提供者: IFormatProvider
    样式: DateTimeStyles
bool TryParseTimeOnly(
    string s,
    IFormatProvider provider,
    DateTimeStyles styles,
    out TimeOnly result)

尝试按给定区域的写法从文本中读取时刻,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null, unreadable text or text that includes a date makes the node report failure.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.
样式DateTimeStyles—White-space options only, such as DateTimeStyles.AllowWhiteSpaces; any other style still throws an System.ArgumentException.

返回

结果真否
结果TimeOnly
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

尝试解析时间间隔

函数

重载 1/2

签名
尝试解析时间间隔(文本: 文本) -> (结果: 真否, 结果: TimeSpan)
bool TryParseTimeSpan(string s, out TimeSpan result)

尝试从形如 [-][d.]hh:mm[:ss[.fffffff]] 的文本中读取时间间隔(不随机器的区域改变),失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null, text in the wrong form or a value out of range makes the node report failure.

返回

结果真否
结果TimeSpan

重载 2/2

签名
尝试解析时间间隔 -> (结果: 真否, 结果: TimeSpan)
    文本: 文本
    提供者: IFormatProvider
bool TryParseTimeSpan(
    string s,
    IFormatProvider provider,
    out TimeSpan result)

尝试按给定区域从形如 [-][d.]hh:mm[:ss[.fffffff]] 的文本中读取时间间隔,失败时报告失败而不是出错中止。

参数

名称类型默认值说明
文本文本—The text to read; null, text in the wrong form or a value out of range makes the node report failure.
提供者IFormatProvider—The culture whose conventions to expect, such as a Globalization.CultureInfo; null uses the invariant culture, the same on every machine.

返回

结果真否
结果TimeSpan
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库

年

函数

重载 1/2

签名
年(值: 时间日期) -> 整数
int Year(DateTime value)

获取时间日期的年份。

参数

名称类型默认值说明
值时间日期—The date and time.

返回

结果整数

重载 2/2

签名
年(值: DateOnly) -> 整数
int Year(DateOnly value)

获取日期的年份。

参数

名称类型默认值说明
值DateOnly—

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
日期时间操作
所属包
标准库