博客园  :: 首页  :: 管理

Powershell编程基础-002-日期及日期格式化

Posted on 2020-08-27 13:37  520_1351  阅读(2517)  评论(0编辑  收藏  举报

在Powershell中,关于日期,时间计算与格式化,常用的如下:

 

$today=Get-Date                                                                #今天的日期,格式:2020年8月27日 13:19:33


echo $today.AddDays(1)                                                   #明天的日期:2020年8月28日 13:33:08
echo $today.AddDays(-1)                                                  #昨天的日期:2020年8月26日 13:33:08
echo $today.ToString('yyyy-MM-dd HH:mm:ss')               #格式化日期时间:2020-08-27 13:33:08

 

综合使用(日期、时间综合计算):

$today=Get-Date    
echo $today.ToString('yyyy-MM-dd HH:mm:ss')                                                          #2020-08-27 13:50:05
echo $today.AddDays(-1).AddHours(-2).AddMinutes(-3).AddSeconds(-4).ToString('yyyy-MM-dd HH:mm:ss')   #2020-08-26 11:47:01

 

 

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/13570910.html