how to get only time from datetime like(2011-04-23 09:30:51:01) in java or javascript or jquery
Asked
Active
Viewed 3.6k times
0
-
5Wondering. Where'd he had to use this? "in java or javascript or jquery" – Kamran Ahmed Nov 26 '13 at 12:07
3 Answers
19
In Java:
SimpleDateFormat parseFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SS");
SimpleDateFormat printFormat = new SimpleDateFormat("HH:mm:ss");
Date date = parseFormat.parse("2011-04-23 09:30:51:01");
System.out.println(printFormat.format(date)); // prints 09:30:51

WhiteFang34
- 70,765
- 18
- 106
- 111
4
Have you seen http://www.quackit.com/javascript/javascript_date_and_time_functions.cfm (or any other JavaScript Date
reference)? In particular see the getHours()
, getMinutes()
and getSeconds()
functions.
Other references:

Community
- 1
- 1

no.good.at.coding
- 20,221
- 2
- 60
- 51
3
In Javascript,
var d = new Date("2011-04-20 09:30:51:01");
d.getHours(); // => 9
d.getMinutes(); // => 30
d.getSeconds(); // => 51
Full details on Javascript's Date object are here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

ktusznio
- 3,585
- 3
- 22
- 21