0

I have a WCF rest service that returns some JSON data and accepts some POST parameter object that are of type DateTime.

When I receive the data which contains datetime fields the date time values are like :

"/Date(1388341800000+0530)/"

  1. How to I format to get the actual date (like 12/30/2013)
  2. When I create a data for POST data like below it fails

    var dataPost = { ID: "121", Name: "Test", DateAdmitted: "12/30/2013" }

This fails (Bad request). But if I pass :

var dataPost = {
ID: "121",
Name: "Test",
DateAdmitted: "/Date(1388341800000+0530)/"
}

I want to be able to pass"12/30/2013" but these are values I deal with in my HTML.

So basically I want to :

  1. Somehow format the received DateTime to readable datetime. ("/Date(1388341800000+0530)/" --> "12/30/2013")

  2. While sending convert the Readable datetime to this format :
    ( "12/30/2013" --> "/Date(1388341800000+0530)/")

Can somebody please help me.

  • Girija
Shankar
  • 841
  • 1
  • 13
  • 39

2 Answers2

1
Step 1: Parse /Date(1388341800000+0530)/ extract 1388341800000 and 0530(offset)

Step 2 : create date object var d = new Date(1388341800000);


var d = new Date(1388341800000); // time
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var nd = new Date(utc + (3600000*offset)); // offset means 0530
nd.toString('yyyy-MM-dd'); // this is your date

Though I have not ran this code but something like this should work for you.

If i am not wrong you have asked the same question for java in another thread. Now if you can pass this properly from js then you need the java answer.

A Paul
  • 8,113
  • 3
  • 31
  • 61
  • This doesnot work, My date has a offset. Can you please give me a code that works. I am not good in JavaScript – Shankar Dec 27 '13 at 16:16
0

to parse the wcf service response and get the date use -

value = new Date(parseInt(value.replace("/Date(", "").replace(")/",""), 10));

to send the wcf request use -

var date = '\\\/Date(' + this.getTime() + ')\\\/';

For your reference, check these stackoveflow question

Community
  • 1
  • 1
Bhalchandra K
  • 2,631
  • 3
  • 31
  • 43