将天添加到预定义的日期 [英] Add Days to predefined date
问题描述
我正在寻找一种以MM / DD / YYYY格式将日期添加到预定义日期的方法。
I'm looking for a way to add days to a predefined date in the format MM/DD/YYYY.
基本上我试图自动化一个查看预定义日期的进程,并添加30天,然后运行一系列命令。我所做的所有搜索都是使用当前日期的例子,但没有一个预定义的日期。
Basically I am trying to automate a process that looks at a predefined date and adds 30 days to it and then runs a series of commands. All the searching around I've done has examples that use the current date, but none for predefined dates.
推荐答案
很简单:
([DateTime]'07/10/2015').AddDays(30)
首先,将一个表示日期的字符串转换为.NET System.DateTime对象,然后使用该对象的 AddDays
方法。注意:当您指定PowerShell的类型名称时,可以省略初始的
System。
- 如果需要的话。
First you cast a string representing your date to a .NET System.DateTime object then you use that object's AddDays
method. Note: when you are specifying type names to PowerShell you can omit the initial System.
- if you want.
这篇关于将天添加到预定义的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!