A LocalDateTime does not have a time zone, and getSecond() only returns the
seconds part of the "human broken down time", so it isn't the same. A
Timestamp represents an instant in time, and the seconds part is seconds
since the epoch. You probably need something like (I did not even attempt
to compile this):

long epochSeconds = ldt.toEpochSeconds(ZoneOffset.UTC);

I believe the nanoseconds part looks correct. If you just want the current
time, you can use:


timestamp = Timestamps.fromMillis(System.currentTimeMillis());

https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/util/Timestamps


Hope that helps!

Evan



On Tue, Oct 31, 2017 at 12:24 PM, Nicholas DiPiazza <
[email protected]> wrote:

> Is this code snippet ok?
>
> LocalDateTime ldt = the date time object we want to send over grpc;
>
> Timestamp.newBuilder().setSeconds(ldt.getSecond())
>       .setNanos(ldt.getNano()))
>     .build()
>
> Is there a helper method to make it easier?
>
>
> On Tue, Oct 31, 2017 at 9:23 AM, Evan Jones <[email protected]>
> wrote:
>
>> I second the recommendation for using Timestamp. If you interact with
>> other languages, some of the libraries provide some some nice helper
>> methods to make working with it fairly straightforward. If you use any
>> Google Cloud APIs, you will end up dealing with Timestamps at some point,
>> so you might as well have fewer unique time types in your system.
>>
>>
>> On Monday, October 30, 2017 at 8:18:41 PM UTC-4, Carl Mastrangelo wrote:
>>>
>>> If you are using Protobuf, there is the  google.protobuf.Timestamp
>>> message type that you can use to send it.
>>>
>>>
>>>
>>> On Friday, October 27, 2017 at 6:31:43 PM UTC-7,
>>> [email protected] wrote:
>>>>
>>>> I would like to know the best way to send DateTime objects to and from
>>>> a GRPC service.
>>>>
>>>> Should I just be sending a string to/from GRPC?
>>>>
>>>> I see there is a Timestamp object but it seems to be not what I'm
>>>> looking for, I think?
>>>>
>>>> Thanks
>>>>
>>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "grpc.io" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/grpc-io/R9_oOEeEWsc/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/grpc-io.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/grpc-io/13a1b845-d921-4323-bc3a-4c84df999d39%40googlegroups.com
>> <https://groups.google.com/d/msgid/grpc-io/13a1b845-d921-4323-bc3a-4c84df999d39%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CACRPLjjdu6ELgeNfiVFoEsFOd6Oww0bLUpobe1dMUxuiq9%2B%3DSA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to