Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

UTC Time, TAI time leap seconds in Java  RSS feed

 
Farrukh Azfar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone

A newbie in Java

I am writing a class through which a user should be able to obtain 1) UTC time 2) TAI time 3) Leap seconds - now I realize that one cannot always obtain these on a platforn - I realize fully that having an available UTC or TAI time is not alway possible - we plan to change our platforms to make it so - in the meantime we need to provide our users with a class that they can use while developing

So here are my questions

1) How does one create a Java Instant with  UTC time - if not UTC then the time on the local machine is fine 
2) How does one create a Java Instant with TAI time - if not TAI then the time on the local machine is fine
3) Is it possible to access Leap seconds from somewhere on the web into Java ?

thanks a million !

Farrukh
 
Paul Clapham
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Farrukh!

I'm not quite clear on what exactly you're asking, but here's a try at an answer:

1. If you use

then that returns the current instant as a Java Instant. However your question didn't ask for the current instant, it just asked for "a Java Instant". So maybe you meant something else? (You should be aware that an Instant doesn't have a time zone.)

2. From my very brief web search it looks to me like TAI time is a fixed number of seconds after UTC. If that's the case then it is a simple matter of adding that number of seconds.

3. Leap seconds? Read the API documentation for the Instant class; it claims (I think) that its underlying time model includes leap seconds. But it looks like you want to display the included leap seconds in some way -- am I right? It doesn't look like there's a method to extract them but the table in the Wikipedia article Leap second should be pretty easy to incorporate into your class.

 
Farrukh Azfar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul and thanks for the welcome and the answer !

Acutally - I don't want to record the leap-seconds - rather I want to beable to access and add the leap seconds to UTC time - to make a TAI time - this class that I am writing will be used by developers only - so this "semi-real" TAI time is fine for them.

In short all I need to do is to be able to access the leap seconds - from somewhere and be fairly sure that they've been updated - so you are saying I should look in the instant class or ?

Farrukh

Paul Clapham wrote:Welcome to the Ranch, Farrukh!

I'm not quite clear on what exactly you're asking, but here's a try at an answer:

1. If you use

then that returns the current instant as a Java Instant. However your question didn't ask for the current instant, it just asked for "a Java Instant". So maybe you meant something else? (You should be aware that an Instant doesn't have a time zone.)

2. From my very brief web search it looks to me like TAI time is a fixed number of seconds after UTC. If that's the case then it is a simple matter of adding that number of seconds.

3. Leap seconds? Read the API documentation for the Instant class; it claims (I think) that its underlying time model includes leap seconds. But it looks like you want to display the included leap seconds in some way -- am I right? It doesn't look like there's a method to extract them but the table in the Wikipedia article Leap second should be pretty easy to incorporate into your class.

 
Paul Clapham
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Farrukh Azfar wrote:In short all I need to do is to be able to access the leap seconds - from somewhere and be fairly sure that they've been updated - so you are saying I should look in the instant class or ?


I would start by reading the API documentation for the Instant class, yes. In particular the section headed "Time-scale". I have to say that I don't understand it, at least not in the context of your question. But if you're working in the area of time representation then you should be able to understand it, or at least the people you're doing the work for should be able to understand it and guide you about how to use it.
 
Farrukh Azfar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Paul - I just discovered there is no facility to get leap seconds out of the Java Instant class -

I did read the guide and another person did too -
- Farrukh

Paul Clapham wrote:
Farrukh Azfar wrote:In short all I need to do is to be able to access the leap seconds - from somewhere and be fairly sure that they've been updated - so you are saying I should look in the instant class or ?


I would start by reading the API documentation for the Instant class, yes. In particular the section headed "Time-scale". I have to say that I don't understand it, at least not in the context of your question. But if you're working in the area of time representation then you should be able to understand it, or at least the people you're doing the work for should be able to understand it and guide you about how to use it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!