Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Java Date object into a JRuby Time object?

Tags:

jruby

Using JRuby, is there a good way to convert a Java Date object into a JRuby Time object? I'm using the latest version of JRuby (1.3.1) and Java SE 6.

like image 516
Megaduck Avatar asked Sep 16 '09 06:09

Megaduck


People also ask

How do you convert a Date object to a calendar object?

getInstance() method the date from calendar object is obtained and using getTime() method it is converted to Date object. Date object to Calendar object, Date d=new Date(1515660075000l);

How do you parse a Date to an object?

Use the toJSON() method to get a string representation of the Date object. Pass the JSON string to the Date() constructor. The Date() constructor will parse the ISO string and will create a Date object.

How do I change TimeZone to Java Util Date?

You can make use of the following DateFormat. SimpleDateFormat myDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); myDate. setTimeZone(TimeZone. getTimeZone("UTC")); Date newDate = myDate.


1 Answers

This should work fine:

Time.at(java.util.Date.new.getTime/1000)
like image 190
Nick Sieger Avatar answered Nov 13 '22 12:11

Nick Sieger