Joda time local zone to utc conversion [closed] - java

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

Related

Get date format with time zone as added hours [closed]

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

java - convert millisecond to localtime [closed]

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

Conversion of milliseconds to a specific date format [closed]

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
How can I convert the current time in milliseconds, which is a Long, to a date in specific format?
The format that I need is yyyy-MM-dd HH:mm. This should be of type Date, not String.
You are confused. The type Date is a number of milliseconds since January 1 1970 midnight UTC. It has no inherent format. There is a default system format for a Date, but you cannot alter it. You will need to format your Date as a String if you need that particular String format.

Working out time between 7am to 3:30pm - JAVA [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I've created this program to calculate the time between startWork and finishWork
but I cant seem to figure out how to calculate time...
This is my Interface.
Just wanting to know a way of approaching this calculation.
Thanks
Use the Duration class from java.time to represent your working time. Let Duration.between() do the calculation for you, passing two LocalTime or two ZonedDateTime objects to it as appropriate. The latter will take transitions to and from summer time (DST) into the calculation if such a transition happens during the working hours.
If the time is entered as for example 1530 or 3:30pm, define a DateTimeFormatter to parse it into LocalTime.
Duration objects can be summed using its plus method, so you can calculate the hourly and monthly working time and so on.
To format the working time into for example 8.5 (for 8 hours 30 minutes), use the toMinutes method, then convert to double before you divide by 60 (I would declare the constant 60 as final double minutesPerHour = TimeUnit.HOURS.toMinutes(1);).
java.time
java.time is the modern Java date and time API. It came out nearly 4 years ago to replace the outdated and poorly designed date and time classes from Java 1.0 and 1.1 from the last years of the previous millennium.
Link: Oracle Tutorial trail Date Time
Use java.time as suggested by Ole V.V.:
String time1 = "07:00:00";
String time2 = "15:30:12";
LocalTime t1 = LocalTime.parse(time1);
LocalTime t2 = LocalTime.parse(time2);
Duration diff = Duration.between(t1, t2);
System.out.println(diff.toString());
Prints:
PT8H30M12S

Formula of currentTimeMillis() in java? [closed]

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.

Categories

Resources