I get the variable date in JS from msql DATETIME as 2017-01-25 20:28:10 var supertime = "2017-01-25 20:28:10" is a string, not a date.

I need to convert to 01.25 20:28

How can this be done easier than regular expressions? How to change the date display format, where the date data is in the JS string string

I get the date json by string in js, so it can be changed both in JS and at the stage of forming a string in php when pulled from the database.

  • You decide on the types. And yet - remember that the meaning and its display are completely different things. Try to do with standard output formatters - for example, dateObj.toLocaleString () may be appropriate ... - Akina
  • one
    Possible duplicate question: Date format in js - Crantisz
  • For dateObj.toLocaleString () you should have a variable of type "time", and I have a string - Typography Manager

2 answers 2

Can I try to convert the request to the desired format right away via DATE_FORMAT ?

For example:

DATE_FORMAT(NOW(),'%m-%d-%Y %h:%i') // 26-01-2017 19:18 
     $item = "2017-01-25 20:28:10"; // из MSQL $time = strtotime($item); $item = date( 'd',$time ).'.'.date( 'm',$time ).' '.date( 'H',$time ).':'.date( 'i',$time ); // получаем 25.01 20:28