Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have question about the current system time. I have software based on command line.
When I run that software, it shows me the time at both the start and end of execution. ie
Start: The current system time is: 1378258559
End: The current system time is : 1378258570
I do not know if the time is in seconds or minutes. How is the 1378258559 is calculated? The difference between the two numbers is 11.
FYI, the current date and time on my system is: 04/09/2013 9:50 AM
This website has a calculator:
It is the number of seconds since January 1st, 1970 at midnight GMT.
The 11, is because something took 11 seconds.
Here's a post explaining why 1970 was chosen along with the definition:
Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds.
Why are dates calculated from January 1st, 1970?
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
This post was edited and submitted for review 7 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I inherited the code developed by my predecessor.
I put the code I developed here, but the time problem occurs because of TimeZone.
The problem is that if you set TimeZone globally, it is predicted that there will be problems in the existing code.
So I want to set TimeZone only for my code
Is there a way to specify Timezone only in my class file or my method?
First of all, my web server operates based on UTC, and existing codes are also based on that standard.
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
Using this, my webserver is pointed to Asia/Seoul and I get the time I want.
However, since this is set globally, there is concern that code written in UTC will have problems.
So it cannot be used.
Also LocalDateTime.now(Zone...); I can get the results I want by using .
However, the zone should be reflected in the already created (DB) time, not now.
In other words, 2022-06-17 15:00 is considered my time as 2022-06-18 00:00.
Rather than specifying +09:00 directly, I want a way that 2022-06-17 15:00 with TimeZone etc can be considered as 2022-06-18 00:00 by the server.
LocaDate.now allow with zone id.
https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#now-java.time.ZoneId-
If its date use zone Id date.toInstant().atZone(ZoneId.of("")).toLocalDateTime()
https://docs.oracle.com/javase/8/docs/api/java/util/Date.html#toInstant--
Use Instant and zone id
Instant instant = Instant.parse("2022-06-18 00:00");
ZoneId zoneId = ZoneId.of("Asia/Tokyo");
LocalDateTime value LocalDateTime.ofInstant(instant, zoneId);
Intent and cause of the question
The time in UTC is entered in the DB.
time : 2022-06-17 15:00
I wanted to convert this to Asia time in a Zoned LocalDateTime.
(+09:00 is required.)
The time I want: 2022-06-18 00:00
However, no matter which method was used, the time in UTC standard was output as it is.
getMyTime.atZone(...).toLocalDateTime ..
Output: 2022-06-17 15:00
While looking for a way, I found that LocalDateTime ignores (or deletes) the "zone" information.
When creating time, it can be created with zone information, but zone information has no meaning after it has already been created.
The solution
From then on, I got closer to the answer, and I found it.
ZonedDateTime.of(localDateTime,ZoneId.systemDefault())
.withZoneSameInstant(ZoneId.of("Asia/Seoul"))
.toLocalDateTime();
Get the zoneDateTime of the base time.
and the key
Create an instant with zone information through withZoneSameInstant and create it as LocalDateTime.
This works perfectly for me.
This question already has answers here:
Convert unix timestamp between different timezones and different DST in Java
(4 answers)
Closed 3 years ago.
I am given epoch time for GMT timezone, i need to convert this time to other timezones based on user time zone provided.
ex- time in GMT = 1551700619
time converted to IST = 1551680819
please help me regarding this.
A few things:
"Epoch time" is a misnomer, and should be abolished from our vocabulary (IMHO). More on this here. What you have is correctly called a "Unix Timestamp".
Timestamps of this form are defined as seconds since the Unix Epoch (1970-01-01 00:00:00 UTC) without accounting for leap seconds.
Because they are based on UTC, they are always in terms of UTC. Presenting one as being in a different time zone is invalid, and can lead to further confusion and corruption as that timestamp is passed around.
The timestamps 1551700619 and 1551680819 are two different points in time, separated by 5 hours and 30 minutes of elapsed time. In other words, if there were events at these two timestamps, and you were in India and on the phone with someone in the United Kingdom, you would both experience the first event, then have to wait 5 hours and 30 minutes, then would both experience the second event.
1551700619 == 2019-03-04T11:56:59Z == 2019-03-04T17:26:59+05:30
1551680819 == 2019-03-04T06:26:59Z == 2019-03-04T11:56:59+05:30
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to know the number of hours in a day when the DST (daylight saving time, summer time) is begins and ends.
Am willing to use java.time. Zone ID is Europe/London. The main intention is:
when DST begins in the spring, we will have 23 hours in one day because clocks are turned forward
conversely when DST ends, we will have 25 hours in one day.
I have an epoch value from which I should find the number of hours. How is it possible?
ZoneId zone = ZoneId.of("Europe/London");
long epochMillis = 1_540_700_000_000L;
LocalDate date = Instant.ofEpochMilli(epochMillis)
.atZone(zone)
.toLocalDate();
int hoursInDay = (int) ChronoUnit.HOURS.between(
date.atStartOfDay(zone),
date.plusDays(1).atStartOfDay(zone));
System.out.println(date + " is " + hoursInDay + " hours");
I didn’t choose the milliseconds since the epoch at random. In this case the output is:
2018-10-28 is 25 hours
Transition to standard time will happen on the last Sunday in October, this year on October 28.
The Australia/Lord_Howe time zone uses 30-minute DST transitions, so in that time zone the day would be either 23.5 hours or 24.5 hours, which in the above will be truncated to 23 and 24. But for London you should be OK until those crazy British politicians decide to do someting similar. :-)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm trying to get data from a website, and when I tried to get the date of a post (expected: 13/06/2014 11:55), i got:
23377855
Can someone help me to convert this number to a date? Thanks!
You can use the standard Java Date API:
long yourNumber = 23377855;
Date date = new Date(yourNumber);
Or you can use Joda Time library, provides much better overall functionality than Java Date API:
long yourNumber = 23377855;
DateTime dt = new DateTime(yourNumber);
Java is expecting milliseconds:
java.util.Date time= new java.util.Date((long)urDateNum*1000);
So you must multiply by 1000
Docs say:
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, 1970, 00:00:00 GMT.
Note:
The cast to long is very important in this situation. Without it the integer overflows.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
hi im trying to convert a date value in milliseconds granuality into java Date using
new Date( millsecs)
the converted value i get is 3 hours behind what it is supposed to be.
I tried using online tools to conver the millisec value i have and it convert to correct date.
Can some one point out what im missing!!!
thnx
A java.util.Date does not have an hour -- at least not in the way that you probably mean. Try the following, and you'll see that the date simply is a point in time that you can specific as X milliseconds since epoch:
long millisec = System.currentTimeMillis();
Date date = new Date(millisec);
long millisec2 = date.getTime();
If I print this date in New York City's time zone, it will correspond to some hour of the day. If I print the same date in GMT, then the hour will be four larger. You probably are printing the value in such a way that you see the same time zone effect.
Think of a date as a point in time. That's a specific number of milliseconds since epoch. Let's pick 3PM PDT as our point in time. This corresponds to 6PM EDT. In other words, all three of those values (millseconds since epoch, 3PM PDT, and 6PM EDT) occupy the same spot on on a timeline.
Or, here's another explanation. 3PM PDT on some day is NOT the same as 3PM EDT on that day. Let's say 3PM PDT corresponds to M milliseconds since epoch. Then, 3PM EDT = M - 10,800,000 milliseconds (that's the number of milleseconds in three hours).