Current time in microseconds

For one of my programs i want to find the current time in microseconds. How do i get this in Java?

The server makes the OS calls that hook into the system processor cycle count,....
Java doesn't directly provide this functionality.Which brings up an interesting question/point (I think).
Since Java provides an sql.TimeStamp class to map to an sql database supporting nanos, how does Java instantiate this class as far as nanos are concerned? Unless the only thing its good for is for READING sql TIMESTAMP values.
My understanding of this is important as it can impact my db design. I would rather have my ejb's create this data in the j2ee server, when doing sql INSERT's, rather than having the db itself do the TIMESTAMP with a trigger (for a variety of reasons, including cache maintenance). But if the nanos are all zero(!)...well, need to use a trigger.
Thanks
-nat

Similar Messages

  • List "View" with current time in column

    Hi.
    I know that list view does not support fields calculated on page load. But I have to realize such functionality.
    Can someone provide options for realizing this?
    "Hack" some internal SQL query, inject JS on a view page, use .NET code somehow?
    Using JS seems as the best solution, but how can I do this?
    Thanks.

    Hi,
    According to your post, my understanding is that you wanted to display the current time in colum.
    The following code snippet for your reference.
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    function date(format, timestamp) {
    var that = this,
    jsdate, f, formatChr = /\\?([a-z])/gi,
    formatChrCb,
    // Keep this here (works, but for code commented-out
    // below for file size reasons)
    //, tal= [],
    _pad = function(n, c) {
    n = n.toString();
    return n.length < c ? _pad('0' + n, c, '0') : n;
    txt_words = ["Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    formatChrCb = function(t, s) {
    return f[t] ? f[t]() : s;
    f = {
    // Day
    d: function() { // Day of month w/leading 0; 01..31
    return _pad(f.j(), 2);
    D: function() { // Shorthand day name; Mon...Sun
    return f.l().slice(0, 3);
    j: function() { // Day of month; 1..31
    return jsdate.getDate();
    l: function() { // Full day name; Monday...Sunday
    return txt_words[f.w()] + 'day';
    N: function() { // ISO-8601 day of week; 1[Mon]..7[Sun]
    return f.w() || 7;
    S: function() { // Ordinal suffix for day of month; st, nd, rd, th
    var j = f.j();
    if (j < 4 || j > 20) {
    return (['st', 'nd', 'rd'])[j % 10 - 1];
    else {
    return 'th';
    w: function() { // Day of week; 0[Sun]..6[Sat]
    return jsdate.getDay();
    z: function() { // Day of year; 0..365
    var a = new Date(f.Y(), f.n() - 1, f.j()),
    b = new Date(f.Y(), 0, 1);
    return Math.round((a - b) / 864e5);
    // Week
    W: function() { // ISO-8601 week number
    var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3),
    b = new Date(a.getFullYear(), 0, 4);
    return _pad(1 + Math.round((a - b) / 864e5 / 7), 2);
    // Month
    F: function() { // Full month name; January...December
    return txt_words[6 + f.n()];
    m: function() { // Month w/leading 0; 01...12
    return _pad(f.n(), 2);
    M: function() { // Shorthand month name; Jan...Dec
    return f.F().slice(0, 3);
    n: function() { // Month; 1...12
    return jsdate.getMonth() + 1;
    t: function() { // Days in month; 28...31
    return (new Date(f.Y(), f.n(), 0)).getDate();
    // Year
    L: function() { // Is leap year?; 0 or 1
    var j = f.Y();
    return j % 4 === 0 & j % 100 !== 0 | j % 400 === 0;
    o: function() { // ISO-8601 year
    var n = f.n(),
    W = f.W(),
    Y = f.Y();
    return Y + (n === 12 && W < 9 ? 1 : n === 1 && W > 9 ? -1 : 0);
    Y: function() { // Full year; e.g. 1980...2010
    return jsdate.getFullYear();
    y: function() { // Last two digits of year; 00...99
    return f.Y().toString().slice(-2);
    // Time
    a: function() { // am or pm
    return jsdate.getHours() > 11 ? "pm" : "am";
    A: function() { // AM or PM
    return f.a().toUpperCase();
    B: function() { // Swatch Internet time; 000..999
    var H = jsdate.getUTCHours() * 36e2,
    // Hours
    i = jsdate.getUTCMinutes() * 60,
    // Minutes
    s = jsdate.getUTCSeconds(); // Seconds
    return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3);
    g: function() { // 12-Hours; 1..12
    return f.G() % 12 || 12;
    G: function() { // 24-Hours; 0..23
    return jsdate.getHours();
    h: function() { // 12-Hours w/leading 0; 01..12
    return _pad(f.g(), 2);
    H: function() { // 24-Hours w/leading 0; 00..23
    return _pad(f.G(), 2);
    i: function() { // Minutes w/leading 0; 00..59
    return _pad(jsdate.getMinutes(), 2);
    s: function() { // Seconds w/leading 0; 00..59
    return _pad(jsdate.getSeconds(), 2);
    u: function() { // Microseconds; 000000-999000
    return _pad(jsdate.getMilliseconds() * 1000, 6);
    // Timezone
    e: function() { // Timezone identifier; e.g. Atlantic/Azores, ...
    // The following works, but requires inclusion of the very large
    // timezone_abbreviations_list() function.
    /* return that.date_default_timezone_get();
    throw 'Not supported (see source code of date() for timezone on how to add support)';
    I: function() { // DST observed?; 0 or 1
    // Compares Jan 1 minus Jan 1 UTC to Jul 1 minus Jul 1 UTC.
    // If they are not equal, then DST is observed.
    var a = new Date(f.Y(), 0),
    // Jan 1
    c = Date.UTC(f.Y(), 0),
    // Jan 1 UTC
    b = new Date(f.Y(), 6),
    // Jul 1
    d = Date.UTC(f.Y(), 6); // Jul 1 UTC
    return ((a - c) !== (b - d)) ? 1 : 0;
    O: function() { // Difference to GMT in hour format; e.g. +0200
    var tzo = jsdate.getTimezoneOffset(),
    a = Math.abs(tzo);
    return (tzo > 0 ? "-" : "+") + _pad(Math.floor(a / 60) * 100 + a % 60, 4);
    P: function() { // Difference to GMT w/colon; e.g. +02:00
    var O = f.O();
    return (O.substr(0, 3) + ":" + O.substr(3, 2));
    T: function() { // Timezone abbreviation; e.g. EST, MDT, ...
    // The following works, but requires inclusion of the very
    // large timezone_abbreviations_list() function.
    /* var abbr = '', i = 0, os = 0, default = 0;
    if (!tal.length) {
    tal = that.timezone_abbreviations_list();
    if (that.php_js && that.php_js.default_timezone) {
    default = that.php_js.default_timezone;
    for (abbr in tal) {
    for (i=0; i < tal[abbr].length; i++) {
    if (tal[abbr][i].timezone_id === default) {
    return abbr.toUpperCase();
    for (abbr in tal) {
    for (i = 0; i < tal[abbr].length; i++) {
    os = -jsdate.getTimezoneOffset() * 60;
    if (tal[abbr][i].offset === os) {
    return abbr.toUpperCase();
    return 'UTC';
    Z: function() { // Timezone offset in seconds (-43200...50400)
    return -jsdate.getTimezoneOffset() * 60;
    // Full Date/Time
    c: function() { // ISO-8601 date.
    return 'Y-m-d\\TH:i:sP'.replace(formatChr, formatChrCb);
    r: function() { // RFC 2822
    return 'D, d M Y H:i:s O'.replace(formatChr, formatChrCb);
    U: function() { // Seconds since UNIX epoch
    return jsdate / 1000 | 0;
    this.date = function(format, timestamp) {
    that = this;
    jsdate = (timestamp === undefined ? new Date() : // Not provided
    (timestamp instanceof Date) ? new Date(timestamp) : // JS Date()
    new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
    return format.replace(formatChr, formatChrCb);
    return this.date(format, timestamp);
    $(function() {
    $('.ms-noWrap').text(date('l, F jS, Y, h:i:s A'));
    </script>
    Note: You should change the class name to fit your environment.
    http://jsfiddle.net/licson0729/jHHsm/
    More reference:
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/580b9c50-f945-4931-b68f-da68d84e766e/how-to-display-current-date-time-in-share-point-using-jquery
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Time in microseconds

    Can someone tell me how can I get the current time to the microsecond level. If I use sy-uzeit, it provides only till the seconds level.
    Thanks..
    Swetha.

    hi,
    5555178 Microseconds = 5.555178 Seconds
    so
    Microseconds = ( 5.555178 / 5555178 )  Seconds
    so convert hours, minutes to seconds and then convert seconds to micro seconds .....
    Regards,
    Santosh

  • Retrieve Computer time in microsecond

    to retrieve computer time i use the function System.currentTimeMillis() but i need the time in microsecond. how could i get that?

    <snip>
    Java 1.5 added nanosecond methods for hardware/OS
    combinations that can support it.Which at current includes none at all :)<snip>
    Are you saying that System.nanoTime() isn't supported at the present time?
    That's not correct - I am running a 3 GB Pentium 4, a relatively recent GigaByte m/b and XP Pro, and get very good microsecond and submicrosecond results from the method.
    I executed 2 consecutuive calls to the method, like so
    startTime = System.nanoTime();
    estimatedTime = System.nanoTime() - startTime;and averaged 100 repetitions.
    Results vary with the manner in which the jvm is executed. Here's a summary of results, to give a feel for what's possible.
    Program Execution From        Nanoseconds (average)
    Commandline                     1300
    CrimsonEditor                    500
    jEdit                            700
    NetBeans IDE 4.1                1050So, depending on the method of execution, nanosecond precision ranges from 500 to 1300 (0.5 microsecond to 1.3 microsecond). Accuracy (repeatability) is not as good - there are outliers in the individual times, probably due to Garbage Collections. However excluding those outliers, times appear reasonably repeatable.

  • ICal (Calendar.app) - Is My Current-Time Marker Missing? Feature Dropped?

    Hello iCalers,
    I recently made the switch to Mountain Lion from Snow Leopard. I was quite a fan of iCal in Snow Leopard—it was one of the reasons I downgraded to Snow Leopard from Lion—but since I have a newer computer that doesn't allow Snow Leopard, and I've got Mountain Lion set up pretty well for me, I'm sticking with Mountain Lion.
    My standard view for things in iCal is "Weekly." In Mountain Lion's incantation, I don't see the red marker that scrolls downwards, the one that corresponded to the current time. I'm wondering: was this feature dropped in Lion/Mountain Lion, or is mine buggy, or is it an out-of-the-way preference somewhere? I peeked in some .plists and com.apple.iCal files—I laugh that Apple still calls it "iCal" at the programming end—but I couldn't see any obvious mention of that time-of-day marker.
    Any ideas?
    I liked it a lot—enough to open a discussion about it!

    Thanks John M,
    It  indeed worked when I made a new user account, so I trashed and deleted my <user>/Library/Calendars folder, as well as <user>/Library/Preferences/com.apple.ical.plist—(backing them up elsewhere beforehand, in case something terrible happened), then re-set-it-up. (Holy cow it's easy to work with iCal after iCloud—literally seconds when it used to be at least a couple of minutes using Google Apps caldav or making an ical backup file and restoring calendars + fixing buggy events). It seems to be all good now.
    A few times in my OS X history I've had issues come up where something is busted and I make a new user account that demonstrates that it's not busted universally. I hadn't even thought of doing that this time. Thanks for the idea!
    May your days be merry and bright!

  • How to check a material being blocked by system at current time?

    hi,
    is there a method to to check a material being blocked by system at current time?
    Thanks!

    Call the function module ENQUEUE_EMMARAE with the required material number. If sy-subrc is not 0, after the function module has executed completely then the material is locked by a different user.
    Please mark points if the solution was useful.
    Regards,
    Manoj

  • Keyboard shortcuts: current day and date, and current time?

    I would like to know keyboard shortcuts for entering current day and date, and current time (separated entries) in Numbers. Something that Excel does easily. Thank you, Ian

    Ian,
    Numbers does not have predefined key command for Insert Date & Time as you can see from this screenshot:
    All menus show the key commands on the very right (if there is a ke command).  You can add you own, custom, key commands by opening system preferences and selecting the Keyboard panel, then the "Keyboard Shortcuts" segment:
    Click the "+" then a modal dialog will appear.   Select the application from the pop, then enter the exact name if the menu item, and, finally, your desired key combination:
    You can do this for any application

  • How to generate current time in the format yyyy-mm-ddThh:mm:ssZ in the xslt

    Hello,
    i am tring to generate current time in the format yyyy-mm-ddThh:mm:ssZ in my xlst file.
    the following info are necessary,
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java"
    version="1.0">
    <xsl:attribute name="generationDate"><xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('yyyy-mm-dd hh:mm:ss'), java:java.util.Date.new())"/></xsl:attribute>
    but java SimpleDateFormat doesnt support yyyy-mm-ddThh:mm:ssZ.
    thanks in advance.

    Hi wwuest,
    I use the following code to generate such a date format :
              try {
                   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                   Date date = sdf.parse(strDate);
                   sdf.applyPattern("yyyy-MM-dd'T'hh:mm:ss");
                   strDate = sdf.format(date);
              } // catching the parse exceptionMaybe you could try this method and see if it pass through xsl with :
    new SimpleDateFormat("yyyy-MM-dd").applyPattern("yyyy-MM-dd'T'hh:mm:ss'Z'")Bye

  • How to get current time in jsp page?

    my problem is :-
    i have a radio buttons with name as 9am, 11am ,1pm, 3pm , 5pm , 7pm , 9pm , 11pm , 1am , 3am ,5am 7am. what ever the current time may be the radio button of four hour plus than current time should be atomatically checked and previous radio buttons should be disabled. for example suppose current time is 11.02am than the radio button of 3pm should be automatically checked and previous radio buttons should be disabled.
    please help me if u can?

    This should work but it needs testing out around midnight ( not sure if it is 00:00 or 24:00):
    <%@ page import="java.util.*" %>
    <html>
    <head><title>Time Page</title>
    </head>
    <body>
    <% Calendar c = Calendar.getInstance();
       c.add(Calendar.HOUR_OF_DAY, 4);
       int h = c.get(Calendar.HOUR_OF_DAY); %>
    The current hour is <%= h %><br>
    <% for (int i=0; i < 24; i++) { %>
       <input type=radio name=time <%= (i < h) ? "disabled" : ""%><%= (i == h) ? "checked" : ""%>><%= (i < 10) ? "0" : ""%><%= i %>:00<br>
    <% } %>
    </body>
    </html>

  • IOS 5 Calendar app current time bar off after time switch

         Here is a issue I have recently noticed. Yesterday we had time fall back one hour. On my Macbook, Iphone 4, and Ipad2, the system time is showing correctly(the time in menu bar on the Mac, and in the top system bar on iOS). On my two Ios5 devices however, in the "Calendar" app, the little bar with the red dot (i refer to as the "current time bar") still shows one hour ahead. So for example the actual time in Los Angeles, CA right now is 3:19 PM but in the calendar app on both Ios devices it shows as 4:19 PM. Keep in mind that the system time is showing 3:19 PM on both of these devices. I logged into the http://www.icloud.com web site and it shows correctly. On my Mac book running MacOSX 10.7.2 everything shows up ok (both system time and iCals current time bar). I am connected to Wi-Fi and 3G. I do have time zone support enabled on all devices, but turning that off did not help anything and I don't see how that could be causing this. What is causing this? Is this a bug in iOS5? Please let me know if you are experiencing the same issue so we can have Apples developers fix this bug. Thanks have a nice afternoon.
    The issue:
    The "Current time bar" in iOS5 Calendar is showing up one hour ahead after time switch as of yesterday (11/5/2011 Los Angeles, CA)
    What I know:
    System time on Mac, Iphone and Ipad shows up as the right time
    Current time bar in iCal on MacOSX 10.7.2  shows right
    Current time bar in Calendar on icloud.com shows right
    Common posts:
    This post seems to be experiencing the same issue.

    I'm having the same issue... the time is right on my phone, however the time-bar is showing DST (one hour ahead). I've restarted the phone... checked my iCloud time zone, etc... even tried turning on/off the Time Zone support not only for the phone but also in the Calendar... nothing.
    So in the end, correct time but the time-bar is incorrect. I hope this is just a bug that needs fixing by Apple...

  • Get Current Time in Eastern Time Zone

    Hi,
    I would like to fetch the current time but in ET timezone (and also i want to handle
    daylight thing automatically).
    So can anyone tell me on this .
    Requirement is to fetch value in ET timezone even your db resides in India or Canada or Germany.
    Regards,
    Sandeep

    You can use current_timestamp at time zone tz_offset('EST'):
    SQL> set linesize 132
    SQL> column ct format a45
    SQL> column ctz format a45
    SQL> ALTER SESSION SET TIME_ZONE = 'Europe/Berlin';
    Session altered.
    SQL> select current_timestamp ct, current_timestamp at time zone tz_offset('EST') ctz from dual;
    CT                                            CTZ
    11-JUL-08 10.20.53.002549 PM EUROPE/BERLIN    11-JUL-08 03.20.53.002549 PM -05:00
    SQL> ALTER SESSION SET TIME_ZONE = 'Canada/Mountain';
    Session altered.
    SQL> select current_timestamp ct, current_timestamp at time zone tz_offset('EST') ctz from dual;
    CT                                            CTZ
    11-JUL-08 02.21.02.344091 PM CANADA/MOUNTAIN  11-JUL-08 03.21.02.344091 PM -05:00
    SQL> SY.

  • Printing current time and date on a pdf document

    I wish for a pdf document to print the current time and date in the same place at the foot of each page, to the following format:
    Aug 04 2009, 5:11 pm.
    How do I do this please? Annoyingly I have managed it in the past, but when I open up my old documents and paste the relevant field into my new document, it either prints the old date/time or else prints the present date/time, but then doesn't refresh the next time I try to print - ie it stays at one date/time.
    I'd like to start again from scratch so that I have a better idea of how it works!!
    Regards
    Tony

    Eureka!
    I now have the answer, and hopefully this will help anybody else with a similar problem.
    In Acrobat:
    Create a text field and place it in the chosen place on the pdf form. Label it "datebox" in the General tab of Text Field Properties, and apply your character styles in the Appearance tab.
    Under the "Advanced" menu, go to "Document Processing" and then "Set Document Actions"
    Click on "Document Will Print" and then hit the "Edit" button. In the "JavaScript Editor" paste the following:
    var myfield=getField("datebox");
    var date=new Date();
    date=util.printd("mmm dd yyyy, h:MM tt", date);
    myfield.value=date;
    Hit OK.
    You have now given the instruction that whenever you print, the field named "datebox" will print the current time and date in the following format:
    Aug 05 2009, 9.37 am
    Regards
    Tony

  • How to check whether current time satisfies the schedule?

    I am working on a task, which is opposite of cron tab. My application is in groovy but can call all Java api. Can you please provide some pointers?
    User is allowed to schedule a rule to be executed the way crontab gives the options. For example he wants the rule to be executed from Monday to Friday from 8 am to 5 pm.
    I can’s schedule in crontabe or Quartz. At run time I have to match, whether the current time satisfy the time condition entered by user.
    I may have to store this information in the database the way we put in the cron. Eg. my tables will have following
    Id|| Policy Id|| seconds|| minutes|| hours|| Day|| Date|| month|| year
    1 || 5 || 1     || 1 || 8-17 || M-F||? || * ||*
    Now while my code is getting executing, how can I match whether the current time matches the condition mentioned above.
    Thanks in advance.

    [Using Span|http://tus.svn.sourceforge.net/viewvc/tus/tjacobs/util/] would make this easy

  • Is it possible to create a shortcut for current time / date with iPhone native apps?

    is it possible to create a shortcut to insert the current time / date in a text such as a Note with iPhone (IOS 6) native apps (not a 3rd. party app)?
    By "shortcut" I mean a combination of characters, the same as under settings/general/keyboards/shortcuts.
    thanks.

    Code that does it is here:
    http://forum.java.sun.com/thread.jsp?forum=48&thread=453846&tstart=0&trange=15
    MOD

  • Possible to show current time during call (not length of call)?

    when i am on a call, the lock screen shows the phone number and the length of time i have been on the call.  is it possible to change this, so that the lock screen shows me the current time (like it does when i am not on the phone)?
    currently, the only way to bring up the current time is to (1) hit the home button (brings up phone controls), (2) slide to unlock, (3) hit home again (to get to enter passcode screen), and (4) enter passcode to see time in green bar at the top of the screen. it's a cumbersome process.

    If I receive a call when locked, after answering, I can see the time in the top status bar...

Maybe you are looking for