James
James

Reputation: 1945

Split Date and time in javascript or jquery

I am getting date as below

2010-10-18,09:11:00

How to split date and time in comma seperated values like 2010,10,18,09,11,00

I tried Date.split('-').join(",") but i get as 2010,10,18 09:11:00

I also want to split time into comma seperated value. So my final output is `2010,10,18,09,11,00

How to achieve this using javascript or jquery? Also i may get date time in either of following format

2010-10-18 09:11:00 or 2010.10.18 09:11:00 

Update`

Sorry i get date as below 2010-10-18 09:11:00

Upvotes: 1

Views: 6196

Answers (1)

aaronman
aaronman

Reputation: 18750

Super easy to do with regex:
var str = "2010-10-18,09:11:00"
var replaced = str.replace(/[-,:\s]/g, ",")

Upvotes: 5

Related Questions