Freigeben über


What formats can I specify for date/time with the tf.exe command-line?

The tf.exe command-line accepts multiple ways of specifying a version - changeset number, T (latest), workspace version, label, and date/time.  For the others it tends to be pretty clear how to specify that version (C123, T, Wsomeworkspace;owner, Lsomelabel) but it may not be clear how we parse the date/time version specifiers.  Since we're a managed app, and since DateTime's parsing is already very extensive, we just call DateTime.TryParse and let it handle all the heavy lifting.  It does an amazingly good job of figuring out many different date formats.

Some US-locale examples:

/version:D11/23/2005   # assumes 00:00:00 for time == midnight == first (not last) second of the day
/version:"D11/23/2005 10:45"
/version:"D11/23/2005 3:45 pm"

However, I tend to recommend using a format that’s not locale-specific on parsing (especially with mm/dd/yyyy vs. dd/mm/yyyy if the day is <= 12) like ISO 8601.  For those who may be worried about potential evil date parsing, this is a good route to take.

/version:D2005-11-23T10:45

RFC1123’s pattern:

/version:"DWed, 23 Nov 2005 15:45:00 GMT"

By default we parse the date/time assuming the local time zone (the client’s time zone, not the server’s, which is different from some other systems) by passing DateTimeStyles.AssumeLocal. If you want to be more specific about the time, you can remove the timezone and specify it in UTC or be more specific on the time zone used.

/version:D2005-11-23T15:45Z
/version:"D2005-11-23 15:45:00Z"
/version:D2005-11-23T15:45+0000
/version:D2005-11-23T10:45-0500

A partial list of patterns that should work fine can be fetched out of your CurrentCulture’s DateTimeFormat property.  For those with Monad installed, you can view them with this one-liner:

MSH C:\> [System.Globalization.CultureInfo]::CurrentCulture.DateTimeFormat | select *Pattern

FullDateTimePattern : dddd, MMMM dd, yyyy h:mm:ss tt
LongDatePattern : dddd, MMMM dd, yyyy
LongTimePattern : h:mm:ss tt
MonthDayPattern : MMMM dd
RFC1123Pattern : ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
ShortDatePattern : M/d/yyyy
ShortTimePattern : h:mm tt
SortableDateTimePattern : yyyy'-'MM'-'dd'T'HH':'mm':'ss
UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z'
YearMonthPattern : MMMM, yyyy
 

If you want to know whether a given string will parse (or confirm it will parse to the correct date), just try DateTime's Parse method on it (I'm on Eastern Standard Time).  Again, for those with Monad, the call would look like this:

MSH C:\> [System.DateTime]::Parse('2005-11-23T15:45+0000')
Wednesday, November 23, 2005 10:45:00 AM

MSH C:\> [System.DateTime]::Parse('2005-13-23T15:45+0000')
Exception calling "Parse" with "1" argument(s): "The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.".
At line:1 char:25
+ [System.DateTime]::Parse( <<<< '2005-13-23T15:45+0000') MSH C:\>

Comments

  • Anonymous
    February 08, 2006
    Now that the RC is out, I thought I'd post a summary with links to version control posts from the last...

  • Anonymous
    September 14, 2007
    Let's recap Items one more time. Items are unique . They have an ID that no other item does. Items are

  • Anonymous
    January 27, 2009
    こんにちは! フォーラム オペレーターの服部清次です。 毎日ブログを更新していると、雑談をするにもネタがなくなってきて困ってしまいます。。。 (^_^;) というわけで、今日は、余談なしで新しいコンテンツを紹介させていただこうと思います。