-3

I have to generate date in specific format in javascript, The required format is "2017-12-07T14:47:00+0530". I have tried using moments but got stuck in time zone field.

moment().format('YYYY-MM-DDTHH:mm:ssZ');  //output 2018-03-06T14:32:45+05:30
Cœur
  • 37,241
  • 25
  • 195
  • 267
Rishabh
  • 89
  • 1
  • 4
  • 11
  • 4
    Please take the [tour] and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) Do your research, [search](/help/searching) for related topics on SO, and give it a go. ***If*** you get stuck and can't get unstuck after doing more research and searching, post a [mcve] of your attempt and say specifically where you're stuck. People will be glad to help. Good luck! – T.J. Crowder Mar 06 '18 at 09:12
  • 1
    I guarantee you this has been asked and answered, if you [search](/help/searching). – T.J. Crowder Mar 06 '18 at 09:12
  • Just by reading the docs `moment().format('YYYY-MM-DDTHH:mm:ssZZ')` – Yury Tarabanko Mar 06 '18 at 09:13
  • Possible duplicate of [Where can I find documentation on formatting a date in JavaScript?](https://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Dominic Mar 06 '18 at 09:14

1 Answers1

1

Take a look at the docs

You want the ZZ timezone format rather than a single Z.

console.log(new moment().format('YYYY-MM-DDTHH:mm:ssZZ')) 
// 2018-03-06T09:14:44+0000
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.js"></script>
Durga
  • 15,263
  • 2
  • 28
  • 52
phuzi
  • 12,078
  • 3
  • 26
  • 50