-4

Is it possible to get the time from the following datetime in javascript?

 2014-11-24 08:30:00

Any help would be appreciated.

UPDATE

Found the solution to my problem in the duplicate:

 datetime.substr(11, 5);
 //returns 08:30

Thanks for all your help!

Bas
  • 29
  • 1
  • 3
  • 1
    Sharing your research helps everyone. Tell us what you've tried and why it didn't meet your needs. This demonstrates that you've taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! Also see [how to ask](http://stackoverflow.com/questions/how-to-ask) – Cerbrus Dec 15 '14 at 09:40
  • use moment.js(http://momentjs.com/) – Bhargav Modi Dec 15 '14 at 09:44

2 Answers2

-1

What about slice? It should be the fastest when you know you always get datetime (and time is in last 8 chars).

var datetime = "2014-11-24 08:30:00";
var time = datetime.slice(-8);

alert(time); // returns "08:30:00"
pavel
  • 26,538
  • 10
  • 45
  • 61
-2
new Date("2014-11-24 08:30:00").getTime();

This code block will get time from your exact date.

İlker Korkut
  • 3,129
  • 3
  • 30
  • 51
  • Depending on what the questioner means by *get the time*, this may not answer the question. `getTime()` does not extract the time part of a Date object, it converts that object into the number of milliseconds elapsed since the epoch instead. – Frédéric Hamidi Dec 15 '14 at 09:43
  • You are right, but question is clear for my situation. Otherwise he must specify the hour or day as a time meaning. – İlker Korkut Dec 15 '14 at 09:46