Time Conversion GMT Epoch - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Time Conversion GMT Epoch

shruti748shruti748 Posts: 7Member
Hi all,
I have timestamps which are stored as seconds since epoch, (Jan 1,
1970 00:00:00 GMT) that I need to be able to work with in human
readable format. e.g. yyyy-mm-dd hh:mm:ss

I would like to have a couple of stored procedures that convert
datestrs to epoch and vice versa.
I need to code this function in C/C++. Could any one help me with this? I would truly appreciate.
Thanks!!!

Comments

  • DB1DB1 Posts: 1,142Member
    : Hi all,
    : I have timestamps which are stored as seconds since epoch, (Jan 1,
    : 1970 00:00:00 GMT) that I need to be able to work with in human
    : readable format. e.g. yyyy-mm-dd hh:mm:ss
    :
    : I would like to have a couple of stored procedures that convert
    : datestrs to epoch and vice versa.
    : I need to code this function in C/C++. Could any one help me with this? I would truly appreciate.
    : Thanks!!!
    :

    can you use strftime( ) or asctime( ) for the conversion to readable form?


    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • shruti748shruti748 Posts: 7Member
    I have not tried that yet. But however I need a function that will convert the date and store in milliseconds first. this will use the epioch since Jan 1, 1970
    Thanks!
  • stoberstober Posts: 9,765Member ✭✭✭
    : I have not tried that yet. But however I need a function that will convert the date and store in milliseconds first. this will use the epioch since Jan 1, 1970
    : Thanks!
    :

    do you want to convert date/time stored in SQL database to C's time_t value? SQL does not store timestamp data that way. convert timestamp to a structure using SQL statements and then to time_t if you want. For example, Sybase SQL has a c function called datecrack that will convert its timestamp data (which is a double) to a datetime structure. You can easily convert that struct to struct tm, and from struct tm to time_t using the mktime() function.
  • shruti748shruti748 Posts: 7Member
    Stober, I can not use SQL statments. The db is enscribed segmented db.
    The user will input the date in the format eg. 1989:12:12:05:06:09 - I will have to store this time in milliseconds since the epicoh Jan 1, 1970 and display back the time to the user during a read command in the format 1989:12:12:05:06:09 etc
    The following link shows exactly what I want to achieve. i have looked at the internet for C/C++ source code but have not been successful. Could you help me with this please?
    Thanks
    http://esqsoft.com/javascript_examples/date-to-epoch.htm
  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2004-4-25 20:3:57[/red][/b][hr]
    : Stober, I can not use SQL statments. The db is enscribed segmented db.
    : The user will input the date in the format eg. 1989:12:12:05:06:09 - I will have to store this time in milliseconds since the epicoh Jan 1, 1970 and display back the time to the user during a read command in the format 1989:12:12:05:06:09 etc
    : The following link shows exactly what I want to achieve. i have looked at the internet for C/C++ source code but have not been successful. Could you help me with this please?
    : Thanks
    : http://esqsoft.com/javascript_examples/date-to-epoch.htm
    :

    I don't think that is in milliseconds but just seconds. I doubt that milliseconds would fit in any kind of natural integer or long. The time_t in time.h is in seconds, not milliseconds. And the value shown on that web page is hours:minutes:seconds -- no milliseconds. To convert is pretty simple -- just fill out a struct tm and call mktime() to get the time_t in seconds. to convert from time_t just call localtime() which returns the struct tm. Once you have that structure it's pretty trivel to format it in whatever way you desire for display.


  • arb123arb123 Posts: 696Member
    : I have timestamps which are stored as seconds since epoch, (Jan 1,
    : 1970 00:00:00 GMT) that I need to be able to work with in human
    : readable format. e.g. yyyy-mm-dd hh:mm:ss

    You might find the date/time parsing functions in this library useful (DateFormat class for C++ or udat.h lib for C). See the API Reference down the left of the page http://oss.software.ibm.com/icu/ .

    Intro to library.
    http://www-106.ibm.com/developerworks/java/library/j-unicode.html

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

  • shruti748shruti748 Posts: 7Member
    Thanks Guys! I am going to make API calls and see if I can achieve what i want. Thanks again for ur input!!!
  • shruti748shruti748 Posts: 7Member
    Sorry guys got me this long to get back in here. Well, the reference to the API was really useful. I am still debugging some problems with it, but I could get going. Thanks again!!!
  • macphersonmacpherson Posts: 302Member
    : Sorry guys got me this long to get back in here. Well, the reference to the API was really useful. I am still debugging some problems with it, but I could get going. Thanks again!!!
    :
    [green]This shows how to roll your own.[/green]
    http://www.maxim-ic.com/appnotes.cfm/appnote_number/1941
Sign In or Register to comment.