DateTime to milliseconds

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DateTime to milliseconds

Mark Volkmann
I know that internally Instant values are stored as milliseconds since  
1970-01-01T00:00Z, but how can I retrieve that millisecond value?

---
Mark Volkmann





------------------------------------------------------------------------------
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DateTime to milliseconds

Brian S O'Neill
In the javadocs:
http://joda-time.sourceforge.net/api-release/org/joda/time/ReadableInstant.html#getMillis()

Mark Volkmann wrote:

> I know that internally Instant values are stored as milliseconds since  
> 1970-01-01T00:00Z, but how can I retrieve that millisecond value?
>
> ---
> Mark Volkmann
>
>
>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>  

------------------------------------------------------------------------------
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DateTime to milliseconds

Mark Volkmann
On Dec 19, 2008, at 11:28 AM, Brian S O'Neill wrote:

> In the javadocs:
> http://joda-time.sourceforge.net/api-release/org/joda/time/ReadableInstant.html#getMillis()

I should have specified that the kind of Instant I'm working with is a  
LocalDate. It doesn't have getMillis. Is the best way to get the  
milliseconds to convert that to a DateTime and then call getMillis  
like this?

long millis = birthday.toDateTimeAtCurrentTime().getMillis();

> Mark Volkmann wrote:
>> I know that internally Instant values are stored as milliseconds  
>> since
>> 1970-01-01T00:00Z, but how can I retrieve that millisecond value?


---
Mark Volkmann





------------------------------------------------------------------------------
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DateTime to milliseconds

Adam Vartanian
> I should have specified that the kind of Instant I'm working with is a
> LocalDate. It doesn't have getMillis.

LocalDate isn't actually an Instant (ie, it doesn't represent a
specific instant in time), it's a representation of an abstract
calendar day with no time or timezone information, so you can't get
the millisecond value for it because it doesn't represent one.

> Is the best way to get the
> milliseconds to convert that to a DateTime and then call getMillis
> like this?
>
> long millis = birthday.toDateTimeAtCurrentTime().getMillis();

Converting it to a DateTime, which does represent a specific instant
in time, via a method like toDateTimeAtCurrentTime() or
toDateTimeAtStartOfDay() is probably what you want to do, yep.

- Adam

------------------------------------------------------------------------------
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DateTime to milliseconds

jodastephen
I would recommend

date.toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis();

You might want to adjust the time zone depending on your requirements.

Stephen



Adam Vartanian wrote:

>> I should have specified that the kind of Instant I'm working with is a
>> LocalDate. It doesn't have getMillis.
>
> LocalDate isn't actually an Instant (ie, it doesn't represent a
> specific instant in time), it's a representation of an abstract
> calendar day with no time or timezone information, so you can't get
> the millisecond value for it because it doesn't represent one.
>
>> Is the best way to get the
>> milliseconds to convert that to a DateTime and then call getMillis
>> like this?
>>
>> long millis = birthday.toDateTimeAtCurrentTime().getMillis();
>
> Converting it to a DateTime, which does represent a specific instant
> in time, via a method like toDateTimeAtCurrentTime() or
> toDateTimeAtStartOfDay() is probably what you want to do, yep.
>
> - Adam
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

------------------------------------------------------------------------------
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...