edenhill / kcat

Generic command line non-JVM Apache Kafka producer and consumer
Other
5.32k stars 475 forks source link

Show message timestamp as UTC ISO8601 format #189

Open MitchelNijdam-Rockstars opened 5 years ago

MitchelNijdam-Rockstars commented 5 years ago

Although I think currently the %T format string token just prints the unix epoch timestamp as read from kafka, for quick debug purposes it would be very useful to have a timestamp in more readable format, for example ISO8601 in UTC. Currently I have to copy paste the timestamps to a converter in order to make sense of it.

If there already is an alternative I'm happy to hear about it!

edenhill commented 4 years ago

That does make sense.

As a workaround you can use jq to reformat the timestamp: https://stackoverflow.com/questions/36853202/jq-dates-and-unix-timestamps

wkujawa commented 4 years ago

I have done a quick change #216 to display human readable form next to epoch. You can build it from https://github.com/wkujawa/kafkacat

Example for format 'Timestamp: %T': Timestamp: 1576098689443 (Wed 2019-12-11 22:11:29.443 CET)

It should be new format specifier but that way is good for me. Feel free to do whatever you like with it. I can also modify it further.

fletchgqc commented 2 years ago

Example of the workaround mentioned by @edenhill:

kcat -C \
  -b $KAFKA_BROKER \
  -t $KAFKA_TOPIC \
  -o beginning \
  -J \
  -e \
| jq '.ts |= (. / 1000 | strftime("%Y-%m-%d %H:%M:%S"))'

Edit: fixed according to the comments directly below

raphaelsolarski commented 1 year ago

Example of the workaround mentioned by @edenhill:

kcat -C \
  -b $KAFKA_BROKER \
  -t $KAFKA_TOPIC \
  -o beginning \
  -J \
  -e \
| jq '.ts |= (. / 1000 | strftime("%Y-%m-%d %H:%m:%S"))'

@fletchgqc @edenhill Thanks a lot. btw. you probably meant "%Y-%m-%d %H:%M:%S"

tbrv commented 11 months ago

For anyone who, like me, has trouble seeing the difference: the original comment by @fletchgqc erroneously uses m (month) not M (minute) for the time format

--------------Δ----
"%Y-%m-%d %H:%m:%S"
"%Y-%m-%d %H:%M:%S