Shop OBEX P1 Docs P2 Docs Learn Events
Time Conversions — Parallax Forums

Time Conversions

ArchiverArchiver Posts: 46,084
edited 2003-02-17 21:06 in General Discussion
Hi All,

I have a device that is giving me GMT in 24 hour format. I want to be able
to convert this to PST and display it in both 24 and 12 hr formats.
Unfortunately, my Stamp math skills aren't up to it. Anyone know how? Tracy,
are you lurking ;-)

Jonathan

www.madlabs.info

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-02-16 22:31
    AM / PM is easy -- divide the hours (in 24-hour format) by 12 -- if the
    result is 0, its AM, if the result is 1, its PM. If its PM, subtract 12 from
    the hours and you are done.

    Original Message

    > I have a device that is giving me GMT in 24 hour format. I want to be able
    > to convert this to PST and display it in both 24 and 12 hr formats.
    > Unfortunately, my Stamp math skills aren't up to it. Anyone know how?
    Tracy,
    > are you lurking ;-)
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-17 04:24
    I believe you need to subtract eight hours to convert GMT to Pacific time.
    You can do it without worrying about negatives by using the modulus operator.
    Like this:

    hours = hours + (24 - TzOffset) // 24

    ... where TzOffset (time zone offset) is the difference between your location
    and GMT. I know the math looks a little funky, but it keeps you from doing a
    comparison.

    After you have the time, you can convert to AM/PM with just a few lines of
    code:

    ampm = hours / 12
    hours = hours // 24
    IF (hours = 0) THEN hours = 12

    This assumes that ampm is a bit flag (0 = am, 1 = pm) and that you're using
    the $PBASIC 2.5 compiler switch.

    -- Jon Williams
    -- Parallax


    In a message dated 2/16/2003 4:10:27 PM Central Standard Time,
    jpeakall@m... writes:

    > Hi All,
    >
    > I have a device that is giving me GMT in 24 hour format. I want to be able
    > to convert this to PST and display it in both 24 and 12 hr formats.
    > Unfortunately, my Stamp math skills aren't up to it. Anyone know how?
    > Tracy,
    > are you lurking ;-)
    >
    > Jonathan
    >
    > www.madlabs.info
    >



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-17 17:04
    Jon,

    Foolishly, I forgot to tell you the time is in HEX format. I am SO sorry to
    be SO thick, but me and math just don't get along, and Stamp math makes my
    head hurt. So, since I am in HEX, can I either convert it, or change the
    formula you wrote?

    Jon, thanks a lot for all the help on this project. Talk about product
    support!

    Jonathan

    www.madlabs.info

    Original Message
    From: <jonwms@a...>
    To: <basicstamps@yahoogroups.com>
    Sent: Sunday, February 16, 2003 8:24 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Time Conversions


    > I believe you need to subtract eight hours to convert GMT to Pacific time.
    > You can do it without worrying about negatives by using the modulus
    operator.
    > Like this:
    >
    > hours = hours + (24 - TzOffset) // 24
    >
    > ... where TzOffset (time zone offset) is the difference between your
    location
    > and GMT. I know the math looks a little funky, but it keeps you from
    doing a
    > comparison.
    >
    > After you have the time, you can convert to AM/PM with just a few lines of
    > code:
    >
    > ampm = hours / 12
    > hours = hours // 24
    > IF (hours = 0) THEN hours = 12
    >
    > This assumes that ampm is a bit flag (0 = am, 1 = pm) and that you're
    using
    > the $PBASIC 2.5 compiler switch.
    >
    > -- Jon Williams
    > -- Parallax
    >
    >
    > In a message dated 2/16/2003 4:10:27 PM Central Standard Time,
    > jpeakall@m... writes:
    >
    > > Hi All,
    > >
    > > I have a device that is giving me GMT in 24 hour format. I want to be
    able
    > > to convert this to PST and display it in both 24 and 12 hr formats.
    > > Unfortunately, my Stamp math skills aren't up to it. Anyone know how?
    > > Tracy,
    > > are you lurking ;-)
    > >
    > > Jonathan
    > >
    > > www.madlabs.info
    > >
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-17 17:08
    So give us a value in hex and tell us what time it represents -- we need to
    know the format so we can help you decode it.


    Original Message

    > Foolishly, I forgot to tell you the time is in HEX format. I am SO sorry
    to
    > be SO thick, but me and math just don't get along, and Stamp math makes my
    > head hurt. So, since I am in HEX, can I either convert it, or change the
    > formula you wrote?
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-17 17:15
    Tracy Allen or someone else smarter than me [noparse][[/noparse]there are many that lurk this
    list] may have an easy way to do it via hex, I would probably just convert
    the hex values to decimal. Something like this:

    hours = hours.HighNib * 10 + hours.LowNib

    -- Jon Williams
    -- Parallax


    In a message dated 2/17/2003 11:05:37 AM Central Standard Time,
    jpeakall@m... writes:

    > Jon,
    >
    > Foolishly, I forgot to tell you the time is in HEX format. I am SO sorry to
    > be SO thick, but me and math just don't get along, and Stamp math makes my
    > head hurt. So, since I am in HEX, can I either convert it, or change the
    > formula you wrote?
    >
    > Jon, thanks a lot for all the help on this project. Talk about product
    > support!
    >
    > Jonathan
    >
    > www.madlabs.info
    >
    >
    Original Message
    > From: <jonwms@a...>
    > To: <basicstamps@yahoogroups.com>
    > Sent: Sunday, February 16, 2003 8:24 PM
    > Subject: Re: [noparse][[/noparse]basicstamps] Time Conversions
    >
    >
    > >I believe you need to subtract eight hours to convert GMT to Pacific time.
    > >You can do it without worrying about negatives by using the modulus
    > operator.
    > > Like this:
    > >
    > >hours = hours + (24 - TzOffset) // 24
    > >
    > >... where TzOffset (time zone offset) is the difference between your
    > location
    > >and GMT. I know the math looks a little funky, but it keeps you from
    > doing a
    > >comparison.
    > >
    > >After you have the time, you can convert to AM/PM with just a few lines of
    > >code:
    > >
    > > ampm = hours / 12
    > > hours = hours // 24
    > > IF (hours = 0) THEN hours = 12
    > >
    > >This assumes that ampm is a bit flag (0 = am, 1 = pm) and that you're
    > using
    > >the $PBASIC 2.5 compiler switch.
    > >
    > >-- Jon Williams
    > >-- Parallax
    > >
    > >
    > >In a message dated 2/16/2003 4:10:27 PM Central Standard Time,
    > >jpeakall@m... writes:
    > >
    > >>Hi All,
    > >>
    > >>I have a device that is giving me GMT in 24 hour format. I want to be
    > able
    > >>to convert this to PST and display it in both 24 and 12 hr formats.
    > >>Unfortunately, my Stamp math skills aren't up to it. Anyone know how?
    > >>Tracy,
    > >>are you lurking ;-)
    > >>
    > >>Jonathan
    > >>
    > >>www.madlabs.info
    >



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-17 21:06
    Hi Jonathan,

    I agree with Jon about the calculation--covert it to decimal first.
    If you also need to do the date, you will have to do a "borrow" that
    might extend to the month and year. E.g., there will be 8 hours in
    GMT on Jan 1 2004 when you will still be in Dec 31 2003!

    I have some Julian date calcs at this URL:
    http://www.emesys.com/BS2math4.htm#JulianDate

    -- Tracy


    >hours = hours.HighNib * 10 + hours.LowNib
    At 11:24 PM -0500 2/16/03, jonwms@a... wrote:
    >hours = hours + (24 - TzOffset) // 24
    >
    >... where TzOffset (time zone offset) is the difference between your location
    >and GMT. I know the math looks a little funky, but it keeps you from doing a
    >comparison.
    >
    >After you have the time, you can convert to AM/PM with just a few lines of
    >code:
    >
    > ampm = hours / 12
    > hours = hours // 24
    > IF (hours = 0) THEN hours = 12


    >Jon,
    >
    >Foolishly, I forgot to tell you the time is in HEX format. I am SO sorry to
    >be SO thick, but me and math just don't get along, and Stamp math makes my
    >head hurt. So, since I am in HEX, can I either convert it, or change the
    >formula you wrote?
    >
    >Jon, thanks a lot for all the help on this project. Talk about product
    >support!
    >
    >Jonathan
    >
    >www.madlabs.info
    >
    >
    Original Message
    >From: <jonwms@a...>
    >To: <basicstamps@yahoogroups.com>
    >Sent: Sunday, February 16, 2003 8:24 PM
    >Subject: Re: [noparse][[/noparse]basicstamps] Time Conversions
    >
    >
    >> I believe you need to subtract eight hours to convert GMT to Pacific time.
    >> You can do it without worrying about negatives by using the modulus
    >operator.
    >> Like this:
    >>
    >> hours = hours + (24 - TzOffset) // 24
    >>
    >> ... where TzOffset (time zone offset) is the difference between your
    >location
    >> and GMT. I know the math looks a little funky, but it keeps you from
    >doing a
    >> comparison.
    >>
    >> After you have the time, you can convert to AM/PM with just a few lines of
    >> code:
    >>
    >> ampm = hours / 12
    >> hours = hours // 24
    >> IF (hours = 0) THEN hours = 12
    >>
    >> This assumes that ampm is a bit flag (0 = am, 1 = pm) and that you're
    >using
    >> the $PBASIC 2.5 compiler switch.
    >>
    >> -- Jon Williams
    >> -- Parallax
    >>
    >>
    >> In a message dated 2/16/2003 4:10:27 PM Central Standard Time,
    >> jpeakall@m... writes:
    >>
    >> > Hi All,
    >> >
    >> > I have a device that is giving me GMT in 24 hour format. I want to be
    >able
    >> > to convert this to PST and display it in both 24 and 12 hr formats.
    >> > Unfortunately, my Stamp math skills aren't up to it. Anyone know how?
    >> > Tracy,
    >> > are you lurking ;-)
    >> >
    >> > Jonathan
    >> >
    >> > www.madlabs.info
    >> >
    >>
    >>
    >>
    >> [noparse][[/noparse]Non-text portions of this message have been removed]
    >>
    >>
    >> To UNSUBSCRIBE, just send mail to:
    >> basicstamps-unsubscribe@yahoogroups.com
    >> from the same email address that you subscribed. Text in the Subject and
    >Body of the message will be ignored.
    >>
    >>
    >> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >>
    >>
    >>
    >>
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the
    >Subject and Body of the message will be ignored.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.