Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to change utc Date in a normal Date

How to change utc Date in a normal Date

Scheduled Pinned Locked Moved C#
helptutorialquestion
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11883281
    wrote on last edited by
    #1

    1448281492 is an Utc-Date (as a decimal?) now i will get these date as a date of my time zone. Can you may help me?

    S L M J U 6 Replies Last reply
    0
    • U User 11883281

      1448281492 is an Utc-Date (as a decimal?) now i will get these date as a date of my time zone. Can you may help me?

      S Offline
      S Offline
      Sascha Lefevre
      wrote on last edited by
      #2

      Member 11916735 wrote:

      1448281492 is an Utc-Date (as a decimal?)

      It's probably the number of ticks. See this DateTime-constructor: DateTime Constructor (Int64, DateTimeKind) (System)[^]

      Member 11916735 wrote:

      now i will get these date as a date of my time zone

      You can either use DateTime.ToLocalTime()[^] or TimeZoneInfo.ConvertTimeFromUtc(..)[^]. For further reading on the topic, see Converting Times Between Time Zones[^].

      If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

      J 1 Reply Last reply
      0
      • U User 11883281

        1448281492 is an Utc-Date (as a decimal?) now i will get these date as a date of my time zone. Can you may help me?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        If those are the number of ticks, then it would be januari the first of your epoch year :)

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

        1 Reply Last reply
        0
        • U User 11883281

          1448281492 is an Utc-Date (as a decimal?) now i will get these date as a date of my time zone. Can you may help me?

          M Offline
          M Offline
          Midi_Mick
          wrote on last edited by
          #4

          You need to know what the number is. Its possible that the number is the number of ticks, and if so, see the answers above. It could also be a Unix timestamp or a Julian Day number, in which case see my tip here[^]

          1 Reply Last reply
          0
          • U User 11883281

            1448281492 is an Utc-Date (as a decimal?) now i will get these date as a date of my time zone. Can you may help me?

            J Offline
            J Offline
            John Torjo
            wrote on last edited by
            #5

            Where is this data coming from? It might actually be a C++ time_t date (seconds since midnight 1970). Best, John

            -- Log Wizard - a Log Viewer that is easy and fun to use!

            1 Reply Last reply
            0
            • U User 11883281

              1448281492 is an Utc-Date (as a decimal?) now i will get these date as a date of my time zone. Can you may help me?

              U Offline
              U Offline
              User 11883281
              wrote on last edited by
              #6

              THANKS! I get it! item.CreationDate is a value from a database: it's the utcDate so now I have this code:

              string einstellDatumTemp = item.creationDate.ToString();
              int unixTimestamp = int.Parse(einstellDatumTemp);
              DateTime unixYear0 = new DateTime(1970, 1, 1);
              long unixTimeStampInTicks = unixTimestamp * TimeSpan.TicksPerSecond;
              DateTime dtUnix = new DateTime(unixYear0.Ticks + unixTimeStampInTicks);

              L 1 Reply Last reply
              0
              • U User 11883281

                THANKS! I get it! item.CreationDate is a value from a database: it's the utcDate so now I have this code:

                string einstellDatumTemp = item.creationDate.ToString();
                int unixTimestamp = int.Parse(einstellDatumTemp);
                DateTime unixYear0 = new DateTime(1970, 1, 1);
                long unixTimeStampInTicks = unixTimestamp * TimeSpan.TicksPerSecond;
                DateTime dtUnix = new DateTime(unixYear0.Ticks + unixTimeStampInTicks);

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                The number looks to me like a standard Windows Time value and equates to the UTC time 12:24:52 Mon Nov 23 2015. You can use any of the standard .NET DateTime methods to display it as local time, according to your timezone.

                1 Reply Last reply
                0
                • U User 11883281

                  1448281492 is an Utc-Date (as a decimal?) now i will get these date as a date of my time zone. Can you may help me?

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  Member 11916735 wrote:

                  as a date of my time zone.

                  Better be very sure that it is your time zone. Good to go if that number is being generated by your computer. But if is coming from another source (computer, database, etc) then you need to determine that.

                  1 Reply Last reply
                  0
                  • S Sascha Lefevre

                    Member 11916735 wrote:

                    1448281492 is an Utc-Date (as a decimal?)

                    It's probably the number of ticks. See this DateTime-constructor: DateTime Constructor (Int64, DateTimeKind) (System)[^]

                    Member 11916735 wrote:

                    now i will get these date as a date of my time zone

                    You can either use DateTime.ToLocalTime()[^] or TimeZoneInfo.ConvertTimeFromUtc(..)[^]. For further reading on the topic, see Converting Times Between Time Zones[^].

                    If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #9

                    Sascha Lefèvre wrote:

                    DateTime-

                    Keep in mind that unfortunately, DateTime, ignores time zone. One should not confuse that with, for example, assuming that it is the same as UTC, because that would be wrong. One should strive to use DateTimeOffset instead.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups