0

Hello i am geting JSON response from web service, with date in this format

20140424T00:00:00

Is it posible to format this date something like this

24.04.2014 in euro format with javaScript

I try to use functions new Date() and toLocaleString() but not success with this format? Any suggestion is welcomed!

7
  • 1
    it will be easier to use a library like momentjs Commented Mar 18, 2015 at 10:02
  • i will try to avoid including more libraries into my project Commented Mar 18, 2015 at 10:06
  • maybe to trim left part and then use some function? Commented Mar 18, 2015 at 10:07
  • found a function toJSON() Commented Mar 18, 2015 at 10:08
  • need something to decode this from json Commented Mar 18, 2015 at 10:21

1 Answer 1

1

I think you can use a simple format function

function formatDate(date){
    return date.replace(/(\d{4})(\d{2})(\d{2}).*/, '$3.$2.$1')
}

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

4 Comments

is it possible to upgrade this code to work with this format 2014-04-24T00:00:00"
@VladimirStus do you want to support both these formats or only one
is some mistcke in JSON response it should be real JSON format 2014-04-24T00:00:00 with dashes - i think now i can use new Date function
tnx your are the best!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.