daylight saving correction removal

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shivaranjan
    New Member
    • Oct 2007
    • 3

    daylight saving correction removal

    Hi,

    I need to calculate the local time without considering the daylight saving into account. Is there any way to do it?. I want to use the ANSI C routines present as this program needs to be ported on many platforms.

    Presently if I call ANCI localtime() routine, it gives the time taking daylight saving into accout ( if dst is active). I want the time without any addition of daylight saving. Advice on the way to achieve this.

    Thanks
    Shiv
  • arnaudk
    Contributor
    • Sep 2007
    • 425

    #2
    Have a look at gmtime() which is part of the time.h library, it returns the current time in UTC. To that you can add a time zone correction to get the local standard time.

    Arnaud

    Comment

    • shivaranjan
      New Member
      • Oct 2007
      • 3

      #3
      Originally posted by arnaudk
      Have a look at gmtime() which is part of the time.h library, it returns the current time in UTC. To that you can add a time zone correction to get the local standard time.

      Arnaud
      Hi ,
      Thanks for the reply. As per your suggestion I searched for time zone correction and found a variable "timezone" which gives time zone correction in one of the time.h. Is this variable supported by all OS. ANSI C does not mentiones this variable but few OS does.

      Or is there any algorithm or way to find time zone correction. please advice.

      Thanks
      Shiv

      Comment

      • arnaudk
        Contributor
        • Sep 2007
        • 425

        #4
        I think the variable "timezone" only works with POSIX (linux/unix) systems.

        If your problem is that you want to find the local standard time in on any computer in any arbitrary timezone from the computer's clock, you could start with localtime() and then work out if that time is daylight time or standard time using daylight saving rules. But that would not be universal either as daylight saving rules vary from country to country so you'd have to know which country the computer is in and you've made no progress. I think there are two equivalent solutions to your problem. To get the local time either
        1) Add the time zone correction gmtime() or
        2) Correct the time from localtime() using using country-specific daylight saving rules.

        In either case, you see that your programs need to know what the time zone/country code is. You can probably determine this using OS-specific system calls or the "timezone" variable which is fine so long as you decide to run your program on only one platform. Otherwise, let the user tell the program what the time zone is or decide that your program will run in a set of countries with the same daylight saving rules only, then you can run it on all platforms.

        Comment

        • shivaranjan
          New Member
          • Oct 2007
          • 3

          #5
          Originally posted by arnaudk
          I think the variable "timezone" only works with POSIX (linux/unix) systems.

          If your problem is that you want to find the local standard time in on any computer in any arbitrary timezone from the computer's clock, you could start with localtime() and then work out if that time is daylight time or standard time using daylight saving rules. But that would not be universal either as daylight saving rules vary from country to country so you'd have to know which country the computer is in and you've made no progress. I think there are two equivalent solutions to your problem. To get the local time either
          1) Add the time zone correction gmtime() or
          2) Correct the time from localtime() using using country-specific daylight saving rules.

          In either case, you see that your programs need to know what the time zone/country code is. You can probably determine this using OS-specific system calls or the "timezone" variable which is fine so long as you decide to run your program on only one platform. Otherwise, let the user tell the program what the time zone is or decide that your program will run in a set of countries with the same daylight saving rules only, then you can run it on all platforms.

          Hi,

          The first option is better, will be going for that. Thanks for the reply and information.

          Shiv

          Comment

          • gnanapoongothai
            New Member
            • Jun 2007
            • 62

            #6
            Is there any function to print the actual time and date when time stamp is given.


            gnanapoongothai .

            Comment

            • arnaudk
              Contributor
              • Sep 2007
              • 425

              #7
              Yes there is: asctime(). Familiarize yourself with time.h if you'll be using time/date functions.

              Arnaud

              Comment

              Working...