views:

76

answers:

2

I am looking for a library or snippet to convert Date/Time format strings from Delphi to .Net. This is for Delphi version 2007.

For example, Delphi 2007 specifies "m" as month, whereas .Net uses "M". However, in Delphi, if the "m" follows an "h", then it represents a minute value.

Are any available, or do I have to roll my own?

+1  A: 

You have to roll your own.

Use these links to make the mapping:

  1. .NET Custom Date and Time Format String
  2. .NET Standard DateTime Format Strings
  3. Delphi SysUtils.FormatDateTime specifiers

--jeroen

Jeroen Pluimers
+3  A: 

ShineOn has a function to do just that:

ConvertDelphiDateTimeFormat(const aFormat: DelphiString): DelphiString;

It also has the inverse:

ConvertClrDateTimeFormat(const aFormat: DelphiString): DelphiString;

It's found in the "Date Functions (SysUtils).pas" file.

The code does indicate it's not 100%

Conversions between date formats:

This is close, but there are some cases where the mapping must be approximate.

For Delphi formats, this means

  • am/pm maps to ampm (that is, must use system setting)
  • a/p is based on current settings, not hardcoded to 'a' or 'p'
  • no control over case in the am/pm or a/p strings
  • no options for how to represent era, they all map to gg
  • no support for z -- it maps to fractional seconds with 3 decimals (zzz)

For CLR formats, this means

  • no support for single-digit years, they map to 2 digit years.
  • no support for 12-hour clock when there is no am/pm symbol, 24-hour is used.
  • no support for fractional seconds, they map to milliseconds (zzz)
  • no support for time zone offsets
Robert Love
It doesn't seem to handle the following:Delphi=yyyymmdd hh:mm, .Net=yyyyMMdd HH:MMI believe it should be:Delphi=yyyymmdd hh:mm, .Net=yyyyMMdd HH:mmNote the incorrect handling of the minutes field.
Joe
Since you have the code it might be worth fixing that specific problem and submitting a patch back the the project.
Robert Love