开发者

how to get only time from datetime like(2011-04-23 09:30:51:01) in java or javascript or jquery [closed]

开发者 https://www.devze.com 2023-02-28 19:09 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_运维百科 Closed 10 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消