0

having problem in converting datetime as required format like bellow

string a = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:sszzz", DateTimeFormatInfo.InvariantInfo);

I can get output like :2016-03-06T14:23:00.000+08:

but when I assign to that sting a to some date time value like below

DateTime dateform= convert.todatetime(a);

I got the output like :03/23/2016 12:00 P.M

for dateform object in C# code

actually I have a java service that service expecting "2016-03-06T14:23:00.000+08:" type of datetime but i am unble to send the format from C# code

service.aptdate=dateform;//here service.aptdate is datetime type so need to pass as it datetime only

when I see the java code they use like

XMLGregorianCalendar x=null;
GregorianCalendar c = new GregorianCalendar();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

c.setTime(new Date());
xCalUploadedDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);

after he get the required format like "2016-03-06T14:23:00.000+08" but in C# I can't get. Any help how I convert.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
madan
  • 81
  • 6
  • I don't think your `a` will be `2016-03-06T14:23:00.000+08` since you don't have any `f` format specifier and `zzz` should return also minutes part of the current timezone UTC Offset. – Soner Gönül Feb 22 '16 at 11:17
  • Are you using json to pass data to your java api? – John Ephraim Tugado Feb 22 '16 at 11:19
  • http://stackoverflow.com/questions/833102/wheres-the-datetime-z-format-specifier This post may help you – Vinothkumar Feb 22 '16 at 11:27
  • Sorry but your question is not consistent. Can you please be more specific? – Soner Gönül Feb 22 '16 at 12:09
  • hi, Soner Gönül thanks for reply here is my problem i need to send the date time to java webservice like (2016-03-06T14:23:00.000+08:)this format.Form java client code he send that format using XMLGregorianCalendar object and sending correctly but i am trying from .net Clinet i am unable to convert that format.every time i sent it takes null value because i am sending datetime format like[03/23/2016 12:00 P.M] .so i need to pass in datetime like (2016-03-06T14:23:00.000+08) format – madan Feb 22 '16 at 23:39
  • hi , John Ephraim Tugado thanks for reply .. i am not using json to java api .Here i am using SOAP and XML to pass the data to Java webservices. – madan Feb 22 '16 at 23:45

0 Answers0