My project is using PDFSharp to normalize creation dates in pdfs. The issue I'm having is that people in different timezones get different offset values than I do.
The problem is PdfSharp allows you to set the creation date but accepts only a DateTime
which it internally calls this on:
public override string ToString()
{
string delta = this.dateTime.ToString("zzz").Replace(':', '\'');
return String.Format("D:{0:yyyyMMddHHmmss}{1}'", this.dateTime, delta);
}
As far as I know DateTime
has no timezone component, but the fact that ToString('zzz')
will return the offset gives me hope.
Is it possible to control what dateTime.ToString('zzz')
returns?
No, basically zzz
will always use the system default time zone. From the documentation:
With
DateTime
values, the "zzz" custom format specifier represents the signed offset of the local operating system's time zone from UTC, measured in hours and minutes. It does not reflect the value of an instance'sDateTime.Kind
property. For this reason, the "zzz" format specifier is not recommended for use withDateTime
values.
So you could change the system default time zone, but that's pretty extreme. Fundamentally this sounds like PdfSharp is broken by design, and you should file a bug. Even just accepting DateTimeOffset
instead of DateTime
would be enough to fix this.
Alternatively, as Jay suggested, you could try to create a class which overrides the ToString
method you've shown us. We can't really tell you how you'd do that without knowing which class it is or what creates the instances of it, but it's definitely a thought.
See more on this question at Stackoverflow