Convert clj-time to java.util.Date


I want to return local current time as java.util.Date. but (clj-time.coerce/to-date) function returns time in UTC . what should I do to return time in a specific timezone?

note : (clj-time.local/local-now ) return the correct time :

(clj-time.coerce/to-date (clj-time.local/local-now))
;#inst "2018-04-29T12:10:49.230-00:00"

;#object[org.joda.time.DateTime 0x5bd0f47 "2018-04-29T16:42:06.926+04:30"]


Good question!

I’ve been reading about java.util.Date here and it appears not to store the timezone. It always represents UTC. Converting to java.util.Date will lose that information. You will have to represent it as a java.util.TimeZone separately.

What exactly are you trying to do with the Date?



I want to store some data contains a “dateTime” field in mongo-db and query data based on a specific time range . but unfortunately mongo can’t encode JodaTime or javatime.localDate (which works properly ). I ended up using ago and periods and clj-time.format functions. and then convert the returned date to java.util.Date. and that worked for me.