在PowerShell中将字符串转换为DateTime [英] String to DateTime conversion in PowerShell

查看:619
本文介绍了在PowerShell中将字符串转换为DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件的时间戳值转换为日期时间,以比较两个日期时间差。

I am trying to convert the time stamp value of a file to date time for comparing two date time differences.

数据将以格式显示24122014_022257 。我需要将其转换为日期时间,以便比较值:

The data would be coming in format 24122014_022257. I need to convert this into date time so that I can compare the values:

$usdate="24122014_022257"   
$dateParts = $usdate -split "_"   
$final = $dateparts[0] + $dateParts[1]   

我该怎么办?

推荐答案

您可以使用ParseExact方法:

You can use the ParseExact method:

[datetime]::ParseExact('24122014_022257','ddMMyyyy_HHmmss',$null)

Wednesday, December 24, 2014 2:22:57 AM

这篇关于在PowerShell中将字符串转换为DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆