how to get only time from datetime like(2011-04-23 09:30:51:01) in java or javascript or jquery [closed]
how to get only time from datetime like(2011-04-23 09:30:51:01) in java or javascript or jquery
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
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:
- Where can I find documentation on formatting a date in JavaScript?
- http://www.elated.com/articles/working-with-dates/
- http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3
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
精彩评论