Case 1 convert 5-digit number to date displayed. Kutools for Excel - Helps You To Stand Out From Crowd Would you like to complete your daily work quickly and perfectly? Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands. Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes. Free upgrade and support for 2 years. Read More Download. Office Tab - Enable Tabbed Reading and Editing in Microsoft Office include Excel One second to switch between dozens of open documents!
Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand. Brings Efficient Tabs to Office include Excel , Just Like Chrome, Firefox, And New Internet Explorer.
Oldest First. Sort comments by. Newest First. Comments 1. No ratings yet. Be the first to rate! about 1 year ago. This comment was minimized by the moderator on the site. Thanks a lot for this helpful article! I've been trying to figure out where the date number originates from and now I know.
More info OK. Learn more. import datetime datetime. fromtimestamp import Java. Date; import java. format currentDate ;. import time int time. mktime time. strptime " " - time. Viewed 10k times. c datetime. Improve this question. asked Jan 25, at Amol Kolekar Amol Kolekar 2, 4 4 gold badges 27 27 silver badges 43 43 bronze badges.
I want C function to convert long value to DateTime e. I agree with Sam, the question is not so clear, "I am using Formating function which one? the long values where are coming from? what kind of encoding?
unix epoch? Looking to this further the value is NOT a long value it has to be a OLE Automation Date double value to make any sense. Which means using DateTime FromOADate double d is what you want to use. No that formating function is different written by our team sorry for bad english or not properly using wordings however problem is solved now thanks you guys.. Add a comment. Sorted by: Reset to default. Highest score default Trending recent votes count more Date modified newest first Date created oldest first.
Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search. I have list with long values for example: , , which I downloaded from web service.
I must convert it to Dates. Unfortunately this way, for example:. The Date constructor click the link! accepts the time as long in milliseconds , not seconds. You need to multiply it by and make sure that you supply it as long. People use various precisions in tracking time as a number since an epoch. So when you obtain some numbers to be interpreted as a count since an epoch, you must determine:. In your case, as others noted, you seem to have been given seconds since the Unix epoch.
But you are passing those seconds to a constructor that expects milliseconds. So the solution is to multiply by 1, Your data seems to be in whole seconds. If we assume an epoch of the beginning of , and if we assume UTC time zone, then 1,,, is the first moment of the first day of September The java.
Date and. Calendar classes bundled with Java are notoriously troublesome. Avoid them. Use instead either the Joda-Time library or the new java. time package bundled in Java 8 and inspired by Joda-Time. Note that unlike j. Date, a DateTime in Joda-Time truly knows its own assigned time zone.
So in the example Joda-Time 2. Then, secondly, we assign a time zone of Paris to adjust. Same moment in the timeline of the Universe, but different wall-clock time. For demonstration, we adjust again, to UTC. We need milliseconds to construct a DateTime. So take your input of seconds, and multiply by a thousand. Note that the result must be a bit long as we would overflow a bit int.
Feed that count of milliseconds to constructor. That particular constructor assumes the count is from the Unix epoch of So adjust time zone as desired, after construction. Never use 3 or 4 letter codes such as EST as they are neither standardized not unique. Dump to console. Note how the date is different in Montréal, as the new day has begun in Europe but not yet in America.
The makers of Joda-Time have asked us to migrate to its replacement, the java. time framework as soon as is convenient. While Joda-Time continues to be actively supported, all future development will be done on the java. time classes and their extensions in the ThreeTen-Extra project. The java-time framework is defined by JSR and built into Java 8 and later. An Instant is a moment on the timeline in UTC with a resolution of nanoseconds. Its epoch is the first moment of in UTC.
Apply an offset-from-UTC ZoneOffset to get an OffsetDateTime. Better yet, if known, apply a time zone ZoneId to get a ZonedDateTime.
It looks like your longs are seconds, and not milliseconds. Date constructor takes time as millis, so. Those are probably timestamps in seconds and not in milliseconds which is required for the java new Date long constructor.
Just multiply them by and you should be allright. The long values, most likely, correspond to Epoch timestamps, and the values are:. One can convert these long values to java. Date , taking into account the fact java. Date uses millisecs — as previously hinted, but with some flaw - like this:. Below are the results of displaying the converted long value to java.
Date without using and using the DateFormat:. toString returns "Thu Jan 15 CET ". Make sure that your values are not in this situation lower than New Date number returns a date that's number milliseconds after 1 Jan Odds are you date format isn't showing hours, minutes, and seconds for you to see that it's just a little bit after 1 Jan You need to parse the date according to the correct parsing routing. I don't know what a is, but if it's seconds after 1 JAN , then multiply it to yield milliseconds.
If it is not, then convert it in some manner to milliseconds after if you want to continue to use java. Works for me. You probably want to multiplz it with , since what you get are the seconds from and you have to pass the milliseconds from jan 1 Date has constructor new Date Long milliseconds - Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, , GMT.
Stack Overflow for Teams — Start collaborating and sharing organizational knowledge. Create a free Team Why Teams? Learn more about Collectives. Learn more about Teams. Converting Long to Date in Java returns Ask Question. Asked 10 years, 11 months ago. Modified 7 months ago. Viewed k times. Anyone know another way to convert it correctly?
java date long-integer. Improve this question. edited Jan 17, at BalusC 1. asked Sep 20, at mmmiki mmmiki 1, 2 2 gold badges 10 10 silver badges 5 5 bronze badges. Could you tell what values do you expect? It looks like you are passing 0 to the constructor.
Some more code might help. mmmiki - you should accept an answer — Stewart. it returns jan 15th , here, not jan 1st.
FYI, the terribly flawed date-time classes such as java. Date , java. Calendar , and java. SimpleDateFormat are now legacy , supplanted by the java. time classes built into Java 8 and later. Add a comment. Sorted by: Reset to default. Highest score default Trending recent votes count more Date modified newest first Date created oldest first. Improve this answer. edited May 24, at answered Sep 20, at BalusC BalusC 1.
toMillis L ; for a cleaner and less magic-numberesque solution.
Highest score default Trending recent votes count more Date modified newest first Date created oldest first. Linked Never use 3 or 4 letter codes such as EST as they are neither standardized not unique. Kutools for Excel brings powerful advanced features Combine workbooks, sum by color, split cell contents, convert date, and so on Read More Download. Hot Network Questions.The [option] tag is being burninated. The Overflow Blog. println date ; Note: Check for 24 hours or 12 hours cycle. Post as a guest Name. I agree to the terms and condition. getInstance ; c.