Sugitime
Sugitime

Reputation: 1888

What time format is this, and how to get it from DatetimePicker

I'm trying to figure out what time format this is, and how I can get it from datetimepicker.

2013-10-28T18:17:00.000-0700

I've gotten this so far:

string theDate = dateTimePicker1.Value.ToString("yyyy-MM-ddTHH:mm:ssssszzz");

but that just outputs this:

2013-10-30T11:28:53-07:00

Any ideas how I can get the output I'm looking for?

Upvotes: 0

Views: 182

Answers (3)

Michael Liu
Michael Liu

Reputation: 55399

It looks like you just need to add milliseconds (.fff) and remove the extra colon in the UTC offset:

string theDate = dateTimePicker1.Value.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz");
theDate = theDate.Remove(theDate.Length - 3, 1);

Note that zzz (unlike zz00) will properly handle time zones like Indian Standard Time, which is UTC+05:30.

Upvotes: 2

CDspace
CDspace

Reputation: 2689

The .Value is a DateTime, so via the Custom Format Docs we get

dateTimePicker1.Value.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz");

That is assuming the -0700 at the end is the timezone offset

Upvotes: 0

L.B
L.B

Reputation: 116138

The format your are looking for is yyyy-MM-ddTHH:mm:ss.fffzzz

Upvotes: 1

Related Questions