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 5 days ago.
Improve this question
In a data stream, I'm receiving date attribute values in milliseconds in Pacific timezone. Like for date = Wed Jan 18 2023 18:00:00 Pacific Time, I'm receiving milliseconds value as 1674064800000. It is milliseconds since 1/1/1970 0:00 PST (I am 100 % sure).
But I want to store this in UTC. How can 1674064800000 millis in PST be converted to 1674093600000 millis in UTC in java/kotlin?
It's a very strange need, as time since 1970-01-01 is usually epoch-time, which is time zone independant.
However, you can achieve your need by adding your offset to a set time, like this:
System.out.println(LocalDate.EPOCH.atStartOfDay(ZoneId.of("America/Vancouver")).toInstant().toEpochMilli() + millis)
Related
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 1 year ago.
Improve this question
How to get the current date time in JMeter formatted like this
2021-03-02T07:57:19+01:00
I have used "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" but it doesn't format as expected
You should use yyyy-MM-dd'T'HH:mm:ssZ or yyyy-MM-dd'T'HH:mm:ssXXX format, for example with time function
${__time(yyyy-MM-dd'T'HH:mm:ssXXX)}
Z Time zone RFC 822 time zone -0800
X Time zone ISO 8601 time zone -08; -0800; -08:00
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 2 years ago.
Improve this question
I need to convert millisecond value to local time
For example, we have this value 1601981597562 when I convert it to Date in UTC it gives me the day will be Oct 10 but in local time it should be Oct 11
new DateTime(1601981597562)
Ref
My question whats the way to convert that timestamp to the local time to be Oct 11 instead of Oct 10
You should use date for this .
Add these codes into your activity.
String localTime = String.valueOf(new Date(timeMillis));
You can use Date to convert Epoch to UTC like so:
long epoch = System.currentTimeMillis();
Date date = new Date(epoch);
System.out.println(date);
Ensure that Date is java.util.Date
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 3 years ago.
Improve this question
I need to convert epoch time in UTC to epoch time in different timezone. Example : 1389556017000 in UTC to epoch time in America/Tijuana timezone.
public static void main(String[] args) {
Long epoch_date = 1389556017000L;
ZonedDateTime date1= Instant.ofEpochMilli(epoch_date)
.atZone(ZoneId.of("America/Tijuana"));
long epoch_second = date1.toInstant().toEpochMilli();
System.out.println("Epoch time in new timezone is :" + epoch_second);
}
My output is same as the input...
Epoch time is an absolute point in time.
It is not relative to any timezone.
Eg - 6:30 PM in India is same as 1:00 PM in England.
The Epoch for both the times is the same.
You can read up more at - https://en.wikipedia.org/wiki/Epoch
2014-01-12T11:46:57-08:00 and 2014-01-12T19:46:57Z are the same time (call it T1).
1970-01-01T00:00:00Z (i.e., the start of the epoch) and 1969-12-31T16:00:00-08:00 (call it T0) are the same time.
Times are internally stored as the number of seconds, milliseconds, whatever, between T0 and the time in question.
There is only one answer to the number of seconds, milliseconds, whatever, between T1 and T0.
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 4 years ago.
Improve this question
I am trying gmt asia/kolkata timemillis convert to utc timemillis but it returns same value. Environment time is asia/kolkata
The epoch is time zone independent. So you should get the same number of milliseconds since the epoch back no matter which time zone you convert to.
So the result you got is correct.
You can try as this
Instant date = Instant.ofEpochMilli(1549362600000l);
LocalDateTime utc = LocalDateTime.ofInstant(date, ZoneOffset.UTC);
You need not to use Joda time api has moved to java 1.8 has implemented the same you can use above same from java.time package
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 9 years ago.
Improve this question
To my knowledge, System.currentTimeMillis()/1000 can show the current time in seconds since
1970-1-1 00:00:00 (YY-MM-DD HH:mm:ss)
For example
2013-10-12 21:30:00 (YY-MM-DD HH:mm:ss)
= 13815846XX (not sure whats X for)
I was wondering how to calculate it. Thanks a lot!!!!
System.currentTimeMillis() just returns the number of milliseconds since the Unix epoch (January 1st 1970, midnight UTC), as a long.
Converting that value into a string is normally the job of something like SimpleDateFormat, via Calendar and Date. Alternatively, look at Joda Time for a nicer date/time API.
If you want to start with a date and get the number of milliseconds since the Unix epoch, you'd use Calendar, set the appropriate fields and then use Calendar.getTimeInMillis(). (Or again, use Joda Time.) Be careful about time zone interactions.
You can use Epoch Converter to check your computations.
A value such as 1381584600 is most likely to be a Unix timestamp, which is the number of seconds (not milliseconds) since the Unix epoch - hence the division by 1000 that you mention.
If this doesn't tell you what you need, please ask a more precise question.