当前位置: 动力学知识库 > 问答 > 编程问答 >

Identifying a DateTime formatting convention

问题描述:

I'm working on a program (we'll call this the PostProcessor) that applies some post-processing to the output of another, closed-source program (we'll call this the Original program. Part of the post-processing involves re-calculating a DateTime value and outputting it in the same format as the original.

For example, the Original may output:

03 : 15 : 30 [h:min:s]

The PostProcessor calculates that the actual time should be 4 hours, 20 minutes and 10 seconds and should output:

04 : 20 : 10 [h:min:s]

The "nice" thing is, despite being mostly a black-box, Original program has some configuration settings. Buried deep within these settings is a string value TimeOutputFormat, which PostProcessor can read.

In the above examples, the TimeOutputFormat string was:

%#H : %M : %S [h:min:s]

Another valid format string I've encountered is:

%q2 min

Which outputs the total minutes to 2 decimal places.


From fiddling around, I've also found the %c format string, which outputs in the form:

1/1/1970 03:15:30 AM

which confirms that the Original program is storing these DateTime values in some form of Unix time object.

What I would like to find out is what formatting system is being used, so I can implement it in my PostProcessor. I'm hoping it's a somewhat standard format since I don't have any documentation. The black-box Original program uses a mixture of Visual C++, .NET, and Python modules (and possibly other technologies I'm not aware of).

Here's a catalog of what I've found so far.

  • # before the letter (i.e. %#d) pads the value with leading 0's
  • # removes padding from a value %d -> 01 but %#d -> 1
  • a digit after the letter (i.e. `%d3') displays decimal digits (if the value has them)

Known formatting strings (from trial/error)

%H - Hour component (not total hours, just the hour component)

%M - Minute component

%S - Second component

%a - Day of week (three letter abbrev.)

%b - Month (three letter abbrev.)

%c - Full date (m/d/yyyy HH:MM AM/PM)

%d - Not sure (outputs "01") (guessing day?)

%e-i Not defined

%j - Not sure (outputs "001") (guessing day out of 365?)

%k-l Not defined

%m - Not sure (outputs "01") (guessing month?)

%q - Total minutes

%p - AM/PM

If anyone can identify this formatting system, I'd greatly appreciate it. I'm going to continue to catalog it for my own use, but it would be nice to have some original documentation if it happens to be a publicly available (and hopefully well-documented) system.

分享给朋友:
您可能感兴趣的文章:
随机阅读: