2

I have a WS made on C# and I need to send this type of format (/Date(1529536171)/) in the POST.

"object": { 
    "data": "data",
    "dateStart": "/Date(1529536171)/",          
}

How can I convert the date that Moment JS give me to that (strange) kind of format??

I tried sent a string with that format but it doesn't work.

Dan Cruz
  • 107
  • 4
  • 10
  • What "1529536171" numbers represent? – Fabio Jun 21 '18 at 00:05
  • 1
    _I need to send this type of format_ - does this mean, that on server side deserialiser will understand this format and will convert it to C# date automatically? – Fabio Jun 21 '18 at 00:07
  • Exactly, the WS of C# was made to receive a Date Object on this (very strange) format. 1529536171 represents I guess the date on Unix format. But everytime y send the POST request, returns me a false indicate that the format of the date is incorrect. – Dan Cruz Jun 21 '18 at 14:55

2 Answers2

1

I think you're referring to a unix timestamp. Moment.js gives you an object that you can format however you'd like. To format it into a timestamp, try this :

moment.unix(yourMomentObject)

This will give you a timestamp.

If you want to format the object to human readable format, simply :

moment.unix(yourMomentObject).format('MM/DD/YYYY')
efru
  • 1,401
  • 3
  • 17
  • 20
1

According to Moment.js' documentation, you can use moment.unix(Number) to create a moment from a Unix timestamp (seconds since the Unix Epoch)

> let myMomentDate = moment.unix(1529543673)
> myMomentDate
moment("2018-06-20T20:14:33.000")

You can also call moment().unix() to get back a Unix timestamp.

> myMomentDate.unix() == 1529543673
true

So you can do the following to get to your desired format:

> '/Date(' + myMomentDate.unix() +')/'
'/Date(1529543673)/'
danypype
  • 443
  • 4
  • 10