简体   繁体   English

Powershell 将数字转换为日期并保存

[英]Powershell convert number to date and save it

I am curious if it's possible to convert numbers to data.我很好奇是否可以将数字转换为数据。 In below example the script would ask sth like this :在下面的例子中,脚本会这样问:

How long user will be active: <add number 30 - meaning for 30 days>

So there must be a variable that holds a current date and add days based on numbers from the input nd, for example, save these data to file.因此必须有一个变量来保存当前日期并根据输入 nd 中的数字添加天数,例如,将这些数据保存到文件中。 I would create a second script that reads this file and remove users if current days are equal do the current date.如果当前日期与当前日期相同,我将创建第二个脚本来读取此文件并删除用户。

I am not sure about conversion from adding days like this :我不确定通过添加这样的天数来转换:

current-date + 30 days = date_in_thefuture :)

any example or where i should look ?任何例子或我应该在哪里看?

$numberofdays = 30
$Temp = (Get-date).AddDays($numberofdays)

Powershell has functions like Get-Date that gives methods such as AddDays() that allows you to do what you are looking for. Powershell 具有像 Get-Date 这样的函数,它提供诸如 AddDays() 之类的方法,使您可以执行所需的操作。

Microsoft documentation on Get-Date 有关 Get-Date 的 Microsoft 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM