解析 MS Project 的日期时间字符串值

问题描述 投票:0回答:1

我需要检索分配给资源的自定义字段的日期时间值。 我可以使用 GetField 从自定义字段中检索值作为字符串值。 该值将使用 MS Project 的 DefaultDateFormat 进行格式化。 因此,日期将像这样表示(示例):

“23 年 11 月 21 日星期二上午 7:43”

有没有办法根据已知的PjDateFormat将String转换为DateTime?

c# office-interop ms-project
1个回答
0
投票

处理未知的默认日期格式的最简单方法是将其更改为您想要的格式,然后为用户重置回来。这是 vba 的基础知识,根据需要翻译成 c#。

Dim CurrentDateFormat As Long

Sub SetDateFormat()
    CurrentDateFormat = Application.DefaultDateFormat
    Application.DefaultDateFormat = pjDate_mm_dd_yy_hh_mmAM
End Sub

Sub ResetDateFormat()
    Application.DefaultDateFormat = CurrentDateFormat
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.