0

I'm working with the Amazon API. I need to convert local time (EDT) to a DateTime that complies with the following documentation from Amazon:

You can specify the FulfillmentDate with or without time zone information:

2006-12-11T09:50:00 - local time zome applies
2006-12-11T09:50:00+02:00 - GMT time zone applies

For locales affected by Daylight Saving  Time, adjust the information, if necessary. 
Daylight Saving Time is not automatically taken into consideration.

I thought I needed to do something like shown in this SO thread, but apparently wrong, because when I upload the date using that method, Amazon shows it as a day before. I can confirm this by using this online converter tool.

For example:

  • My local time is "7/25/2012 00:00:00" (EDT).

  • Using above SO method, and formatted, it's now "2012-07-25T01:00:00-04:00".

  • But it converts to the 24th, specifically "Tuesday, July 24, 2012 at 21:00:00".

Obviously I'm doing something wrong here - I'd appreciate if someone can enlighten me.

Thank you!

Community
  • 1
  • 1
Rivka
  • 2,172
  • 10
  • 45
  • 74

3 Answers3

1

I would recommend using:

String xmlDateString = XmlConvert.ToString(DateTime.UtcNow,XmlDateTimeSerializationMode.Local);
Steen Tøttrup
  • 3,755
  • 2
  • 22
  • 36
  • Thanks. But that gives me "2012-07-25T00:00:00-04:00" and the same date when I convert: 24th - see http://www.timeanddate.com/worldclock/converted.html?iso=20120725T00&p1=0&p2=861&p3=&p4=&p5=&p6=&p7=&p8=&p9=&p10=&p11=&p12= – Rivka Jul 26 '12 at 11:32
  • Not understanding your question I guess. Is the question not about getting the right format for the date when pushed to the API ? If not, is it the timezone you have to convert to GMT ?If you push the 25th, it might get "converted" to the 24th or 26th depending on what timezone it is shown as. 2012-07-25 00:00:00 at -04:00 would be 2012-07-24 23:00:00 at -05:00. – Steen Tøttrup Jul 26 '12 at 11:49
  • See, I'm not sure I know the question myself - I believe we have the format right. I only know that when I send the date, "2012-07-25T00:00:00-04:00" to the API, it converts it to the 24th. That makes me think the DateTime needs to be converted to GMT. – Rivka Jul 26 '12 at 11:55
  • Ah, that' always the challenge of globalization/localization/etc. When you say the API converts the date, how do you know? Can you see it somewhere in an UI ? Or do you get it back calling the API ? – Steen Tøttrup Jul 26 '12 at 11:57
  • I see it in the UI - on Amazon. – Rivka Jul 26 '12 at 12:09
  • Okay, and it is shown there without any timezone information? And you have no way of choosing the timezone you are in? – Steen Tøttrup Jul 26 '12 at 12:10
  • Yup, confirmed with Amazon dates are being shown in PDT. Wish they would standardize their formats there - some dates specify the time zone, while others don't - could avoid such confusion. Thank you @SteenT and @OliverVogel! – Rivka Aug 01 '12 at 07:58
1

Obviously Amazon converts your local time information back to UTC time (which is based on your input 4 hours back in time: Tuesday, July 24, 2012 at 21:00:00 and therefore correct).

Which result have you been expected?

Oliver Vogel
  • 1,988
  • 1
  • 20
  • 33
  • That does make sense... I just didn't know Amazon displays their dates in UTC time by default. I was actually trying to confirm which time zone they use. I'll post back if & when I receive a definite answer from them. – Rivka Jul 26 '12 at 18:44
  • 1
    You could always try retrieving your date back from the API, that should show you whether or not they "damaged" your data. – Steen Tøttrup Jul 27 '12 at 06:16
0

I think I can introduce a "joda time" project written by Jon Skeet. You can refer to link pros and cons of joda time

Community
  • 1
  • 1
cat916
  • 1,363
  • 10
  • 18