Skip to content
Advertisement

Tag: time

Convert java.time.Instant to java.sql.Timestamp without Zone offset

In the application I am developing, I need to convert java.time.Instant object to java.sql.Timestamp. When I create Instant object like: I receive something like 2017-03-13T14:28:59.970Z. And when I try to create Timestamp object like this: I receive something like 2017-03-13T16:28:59.970Z. The same result but with an additional 2 hour delay. Can someone explain why this is happening and provide me

Convert a Julian Date to an Instant

I’m running into a situation where I would like to convert from a Julian date to an java.time.Instant (if that makes sense), or some Java time that can be more easily understood. My understanding of what a Julian date is comes from reading the Wikipedia page. There are bunch of different variants, and the date I am trying to read

How to sort a list of months with years

I have a list of months with years such as: [12-2014,11-2012,5-2014,8-2012] and I have to sort them with the most recent on top (or the latest date on top) eg. [12-2014,5-2014,11-2012,8-2012] . Does anybody have any idea on how to do this in Java efficiently? EDIT: The class YearMonth is not available, I’m on Java 7 Answer Since you are

Convert seconds into T1H15M5S (ISO_8601)

I would like to convert a number of seconds into ISO_8601/Duration in Java. http://en.wikipedia.org/wiki/ISO_8601#Durations Are there any existing methods to do it that are already built in? Answer Since ISO 8601 allows for the individual fields in a duration string to overflow, you could just prepend “PT” to the number of seconds and append “S”: This will output “PT4711S”, which

How to know if now time is between two hours?

I have a now time: And I have some hour constants, for example, 23 and 8 (it’s 11pm or 23:00, 8am or 08:00). How I can know is now time between it’s two hour constants? It need to run some code of program or not to run if now time is between in two hours, for example, do not run

How to convert UTC time into local time in Java?

I have time coming from gpslocation service in 1352437114052 format. Can some one tell me how to convert this into local time either in Java or Matlab or Excel. Answer Create a new Date from your milliseconds since epoch. Then use a DateFormat to format it in your desired timezone.

Date formatting according to country habbits

We create J2SE application that has to format the date and time according to custom the country from which users come from. I want to ask how to solve this thing in Java? Probably I’ll use SimpleDateFormat, but I wonder if it is possible to get format string in somehow simpler way than to have all format strings for each

In Java, what is the fastest way to get the system time?

I’m developing a system that often use the system time because the Delayed interface. What is fastet way to get the time from system? Currently I’m using Calendar.getInstance().getTimeInMillis() every time I need to get the time, but I don’t know if there is a faster way. Answer System.currentTimeMillis() “Returns the current time in milliseconds”. Use this to get the actual

Advertisement