function to get time in seconds and milliseconds

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default function to get time in seconds and milliseconds

    Hi,

    Is there a function in Solaris 8 that would return time in seconds (since
    1970) and also contain millisecond part of the time. I know there are
    functions to obtain time in seconds but I don't think they contain
    millisecond part.

    Would it be possible for you to also supply sample code.

    Thanks!


    John Smith Guest

  2. Similar Questions and Discussions

    1. Shock Player has slow buffering time of 50 seconds
      i looked in add-ins for internet explorer 7 and i do not have adobe flash player but i do have shockwave flash object publisher: adobe systems...
    2. Time Format in datagrid (Hours, Minutes, Seconds)
      I have a column in my database that stores total seconds. I want to bind this colum to my datagrid. Is there a way to have the time show as hours,...
    3. #25150 [Fbk->NoF]: Maximum execution time of 30 seconds exceeded
      ID: 25150 Updated by: sniper@php.net Reported By: alain at antinea dot org -Status: Feedback +Status: ...
    4. #25150 [NEW]: Maximum execution time of 30 seconds exceeded
      From: alain at antinea dot org Operating system: Linux PHP version: 4.3.2 PHP Bug Type: *General Issues Bug description: ...
    5. Time compare using milliseconds
      Hello all, I have two timestamps that look like this: 08:42:38:624 08:42:39:437 I need to find out the difference. I have never worked with...
  3. #2

    Default function to get time in seconds and milliseconds

    Hi,

    Is there a function in Solaris 8 that would return time in seconds (since
    1970) and also contain millisecond part of the time. I know there are
    functions to obtain time in seconds but I don't think they contain
    millisecond part.

    Would it be possible for you to also supply sample code.

    Thanks!


    John Smith Guest

  4. #3

    Default Re: function to get time in seconds and milliseconds

    On Sat, 5 Jul 2003, John Smith wrote:
    > Is there a function in Solaris 8 that would return time in seconds (since
    > 1970) and also contain millisecond part of the time. I know there are
    > functions to obtain time in seconds but I don't think they contain
    > millisecond part.
    You can use gettimeofday(), but I don't think there's a
    guarantee of sub-second resolution. Why do you need this
    resolution? Odds are there are better ways than time since
    the epoch...

    --
    Rich Teer, SCNA, SCSA

    President,
    Rite Online Inc.

    Voice: +1 (250) 979-1638
    URL: [url]http://www.rite-online.net[/url]

    Rich Teer Guest

  5. #4

    Default Re: function to get time in seconds and milliseconds

    On Sat, 5 Jul 2003, John Smith wrote:
    > Is there a function in Solaris 8 that would return time in seconds (since
    > 1970) and also contain millisecond part of the time. I know there are
    > functions to obtain time in seconds but I don't think they contain
    > millisecond part.
    You can use gettimeofday(), but I don't think there's a
    guarantee of sub-second resolution. Why do you need this
    resolution? Odds are there are better ways than time since
    the epoch...

    --
    Rich Teer, SCNA, SCSA

    President,
    Rite Online Inc.

    Voice: +1 (250) 979-1638
    URL: [url]http://www.rite-online.net[/url]

    Rich Teer Guest

  6. #5

    Default Re: function to get time in seconds and milliseconds

    "Rich Teer" <rich.teer@rite-group.com> wrote in message
    news:Pine.GSO.4.44.0307051645400.448-100000@zaphod.rite-group.com...
    > On Sat, 5 Jul 2003, John Smith wrote:
    >
    > > Is there a function in Solaris 8 that would return time in seconds
    (since
    > > 1970) and also contain millisecond part of the time. I know there are
    > > functions to obtain time in seconds but I don't think they contain
    > > millisecond part.
    >
    > You can use gettimeofday(), but I don't think there's a
    > guarantee of sub-second resolution. Why do you need this
    > resolution? Odds are there are better ways than time since
    > the epoch...
    Hi,

    The reason why I needed this type of resolution is because I am writing a
    simulator and the proprietary protocol that I am working with requires me to
    put time in seconds part + millisecond part in each message header. Does
    Solaris even keep time in millisecond resolution?


    John Smith Guest

  7. #6

    Default Re: function to get time in seconds and milliseconds

    "Rich Teer" <rich.teer@rite-group.com> wrote in message
    news:Pine.GSO.4.44.0307051645400.448-100000@zaphod.rite-group.com...
    > On Sat, 5 Jul 2003, John Smith wrote:
    >
    > > Is there a function in Solaris 8 that would return time in seconds
    (since
    > > 1970) and also contain millisecond part of the time. I know there are
    > > functions to obtain time in seconds but I don't think they contain
    > > millisecond part.
    >
    > You can use gettimeofday(), but I don't think there's a
    > guarantee of sub-second resolution. Why do you need this
    > resolution? Odds are there are better ways than time since
    > the epoch...
    Hi,

    The reason why I needed this type of resolution is because I am writing a
    simulator and the proprietary protocol that I am working with requires me to
    put time in seconds part + millisecond part in each message header. Does
    Solaris even keep time in millisecond resolution?


    John Smith Guest

  8. #7

    Default Re: function to get time in seconds and milliseconds


    "John Smith" <John_Smith273@cox.net> wrote in message
    news:wbKNa.120012$MJ5.8291@fed1read03...
    > The reason why I needed this type of resolution is because I am writing a
    > simulator and the proprietary protocol that I am working with requires me
    to
    > put time in seconds part + millisecond part in each message header. Does
    > Solaris even keep time in millisecond resolution?
    The 'gettimeofday' function will give you the platform's best guess of
    the current time in seconds and microseconds. What resolution the system
    actually has will vary based on the hardware.

    I tried this program on a few sparch Solaris machines:

    #include <time.h>
    #include <sys/time.h>

    int main(void)
    {
    struct timeval t1, t2;
    gettimeofday(&t1, NULL);
    do gettimeofday(&t2, NULL); while (t1.tv_usec==t2.tv_usec);
    printf("Resolution guess, %d usec\n", t2.tv_usec-t1.tv_usec);
    }

    And I usually get '1 usec', suggesting that the machine has at least
    microsecond resolution.

    Of course, the accuracy with respect to UTC will depend upon how well
    the clock is synchronized to UTC. But it should be suitable for figuring out
    the time between events that all take place on the same machine.

    DS


    David Schwartz Guest

  9. #8

    Default Re: function to get time in seconds and milliseconds


    "John Smith" <John_Smith273@cox.net> wrote in message
    news:wbKNa.120012$MJ5.8291@fed1read03...
    > The reason why I needed this type of resolution is because I am writing a
    > simulator and the proprietary protocol that I am working with requires me
    to
    > put time in seconds part + millisecond part in each message header. Does
    > Solaris even keep time in millisecond resolution?
    The 'gettimeofday' function will give you the platform's best guess of
    the current time in seconds and microseconds. What resolution the system
    actually has will vary based on the hardware.

    I tried this program on a few sparch Solaris machines:

    #include <time.h>
    #include <sys/time.h>

    int main(void)
    {
    struct timeval t1, t2;
    gettimeofday(&t1, NULL);
    do gettimeofday(&t2, NULL); while (t1.tv_usec==t2.tv_usec);
    printf("Resolution guess, %d usec\n", t2.tv_usec-t1.tv_usec);
    }

    And I usually get '1 usec', suggesting that the machine has at least
    microsecond resolution.

    Of course, the accuracy with respect to UTC will depend upon how well
    the clock is synchronized to UTC. But it should be suitable for figuring out
    the time between events that all take place on the same machine.

    DS


    David Schwartz Guest

  10. #9

    Default Re: function to get time in seconds and milliseconds

    On Sat, 05 Jul 2003 19:43:03 -0400, John Smith wrote:
    > Hi,
    >
    > Is there a function in Solaris 8 that would return time in seconds
    > (since 1970) and also contain millisecond part of the time.
    Try gettimeofday.

    Mike
    Michael B Allen Guest

  11. #10

    Default Re: function to get time in seconds and milliseconds

    On Sat, 05 Jul 2003 19:43:03 -0400, John Smith wrote:
    > Hi,
    >
    > Is there a function in Solaris 8 that would return time in seconds
    > (since 1970) and also contain millisecond part of the time.
    Try gettimeofday.

    Mike
    Michael B Allen Guest

  12. #11

    Default Re: function to get time in seconds and milliseconds

    In article <wbKNa.120012$MJ5.8291@fed1read03>,
    John Smith <John_Smith273@cox.net> wrote:
    >>
    >> You can use gettimeofday(), but I don't think there's a
    >> guarantee of sub-second resolution. Why do you need this
    >> resolution? Odds are there are better ways than time since
    >> the epoch...
    >
    >The reason why I needed this type of resolution is because I am writing a
    >simulator and the proprietary protocol that I am working with requires me to
    >put time in seconds part + millisecond part in each message header. Does
    >Solaris even keep time in millisecond resolution?
    No, it keeps time in sub-microsecond resolution.

    --
    EMail:joerg@schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
    [email]js@cs.tu-berlin.de[/email] (uni) If you don't have iso-8859-1
    [email]schilling@fokus.fraunhofer.de[/email] (work) chars I am J"org Schilling
    URL: [url]http://www.fokus.fraunhofer.de/usr/schilling[/url] [url]ftp://ftp.berlios.de/pub/schily[/url]
    Joerg Schilling Guest

  13. #12

    Default Re: function to get time in seconds and milliseconds

    In article <wbKNa.120012$MJ5.8291@fed1read03>,
    John Smith <John_Smith273@cox.net> wrote:
    >>
    >> You can use gettimeofday(), but I don't think there's a
    >> guarantee of sub-second resolution. Why do you need this
    >> resolution? Odds are there are better ways than time since
    >> the epoch...
    >
    >The reason why I needed this type of resolution is because I am writing a
    >simulator and the proprietary protocol that I am working with requires me to
    >put time in seconds part + millisecond part in each message header. Does
    >Solaris even keep time in millisecond resolution?
    No, it keeps time in sub-microsecond resolution.

    --
    EMail:joerg@schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
    [email]js@cs.tu-berlin.de[/email] (uni) If you don't have iso-8859-1
    [email]schilling@fokus.fraunhofer.de[/email] (work) chars I am J"org Schilling
    URL: [url]http://www.fokus.fraunhofer.de/usr/schilling[/url] [url]ftp://ftp.berlios.de/pub/schily[/url]
    Joerg Schilling Guest

  14. #13

    Default Re: function to get time in seconds and milliseconds


    "John Smith" <John_Smith273@cox.net> wrote in message news:2oJNa.119999$MJ5.1555@fed1read03...
    > Hi,
    >
    > Is there a function in Solaris 8 that would return time in seconds (since
    > 1970) and also contain millisecond part of the time. I know there are
    > functions to obtain time in seconds but I don't think they contain
    > millisecond part.
    >
    > Would it be possible for you to also supply sample code.
    >
    > Thanks!
    >
    >
    gethrtime()
    [url]http://groups.google.com/groups?selm=36822F3A.DBFF0811%40tibam.elex.co.il[/url]
    [url]http://groups.google.com/groups?selm=368734F0.70B29CE2%40tibam.elex.co.il[/url]

    getrusage()
    See C/C++ Program Perfometer :
    [url]http://sourceforge.net/projects/cpp-perfometer[/url]
    [url]http://alexvn.freeservers.com/s1/perfometer.html[/url]


    ==========================================
    Alex Vinokur
    mailto:alexvn@connect.to
    [url]http://www.simtel.net/pub/oth/19088.html[/url]
    [url]http://sourceforge.net/users/alexvn[/url]
    ==========================================


    Alex Vinokur Guest

  15. #14

    Default Re: function to get time in seconds and milliseconds


    "John Smith" <John_Smith273@cox.net> wrote in message news:2oJNa.119999$MJ5.1555@fed1read03...
    > Hi,
    >
    > Is there a function in Solaris 8 that would return time in seconds (since
    > 1970) and also contain millisecond part of the time. I know there are
    > functions to obtain time in seconds but I don't think they contain
    > millisecond part.
    >
    > Would it be possible for you to also supply sample code.
    >
    > Thanks!
    >
    >
    gethrtime()
    [url]http://groups.google.com/groups?selm=36822F3A.DBFF0811%40tibam.elex.co.il[/url]
    [url]http://groups.google.com/groups?selm=368734F0.70B29CE2%40tibam.elex.co.il[/url]

    getrusage()
    See C/C++ Program Perfometer :
    [url]http://sourceforge.net/projects/cpp-perfometer[/url]
    [url]http://alexvn.freeservers.com/s1/perfometer.html[/url]


    ==========================================
    Alex Vinokur
    mailto:alexvn@connect.to
    [url]http://www.simtel.net/pub/oth/19088.html[/url]
    [url]http://sourceforge.net/users/alexvn[/url]
    ==========================================


    Alex Vinokur Guest

  16. #15

    Default Re: function to get time in seconds and milliseconds

    In article <pan.2003.07.06.01.06.08.423187.4856@ioplex.com> ,
    Michael B Allen <mba2000@ioplex.com> writes:
    > On Sat, 05 Jul 2003 19:43:03 -0400, John Smith wrote:
    >
    >> Hi,
    >>
    >> Is there a function in Solaris 8 that would return time in seconds
    >> (since 1970) and also contain millisecond part of the time.
    >
    > Try gettimeofday.
    >
    > Mike

    I've used "clock_gettime"; that returns time in seconds and nanoseconds.

    --
    Edward Lloyd Hillman
    Signature?!? I don't need no stinking signature!!
    <mailto:ehillman@iamdigex.net>
    Edward Lloyd Hillman Guest

  17. #16

    Default Re: function to get time in seconds and milliseconds

    In article <pan.2003.07.06.01.06.08.423187.4856@ioplex.com> ,
    Michael B Allen <mba2000@ioplex.com> writes:
    > On Sat, 05 Jul 2003 19:43:03 -0400, John Smith wrote:
    >
    >> Hi,
    >>
    >> Is there a function in Solaris 8 that would return time in seconds
    >> (since 1970) and also contain millisecond part of the time.
    >
    > Try gettimeofday.
    >
    > Mike

    I've used "clock_gettime"; that returns time in seconds and nanoseconds.

    --
    Edward Lloyd Hillman
    Signature?!? I don't need no stinking signature!!
    <mailto:ehillman@iamdigex.net>
    Edward Lloyd Hillman Guest

  18. #17

    Default Re: function to get time in seconds and milliseconds

    "John Smith" <John_Smith273@cox.net> wrote in message
    news:2oJNa.119999$MJ5.1555@fed1read03...
    > Hi,
    >
    > Is there a function in Solaris 8 that would return time in seconds (since
    > 1970) and also contain millisecond part of the time. I know there are
    > functions to obtain time in seconds but I don't think they contain
    > millisecond part.
    >
    > Would it be possible for you to also supply sample code.
    >
    > Thanks!
    Thank you all for your help! I really appreciated the feedback you have
    provided.


    John Smith Guest

  19. #18

    Default Re: function to get time in seconds and milliseconds

    "John Smith" <John_Smith273@cox.net> wrote in message
    news:2oJNa.119999$MJ5.1555@fed1read03...
    > Hi,
    >
    > Is there a function in Solaris 8 that would return time in seconds (since
    > 1970) and also contain millisecond part of the time. I know there are
    > functions to obtain time in seconds but I don't think they contain
    > millisecond part.
    >
    > Would it be possible for you to also supply sample code.
    >
    > Thanks!
    Thank you all for your help! I really appreciated the feedback you have
    provided.


    John Smith Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139