Question: I can calculate the time in milliseconds with the following Ruby snippet:

```ruby
$ irb
> require 'date'
 => true 
> Date.new(2014,9,5).to_time
 => 2014-09-05 00:00:00 +0200
> Date.new(2014,9,5).to_time.to_i * 1000
 => 1409868000000

```

`1409868000000` is the desired result.  

How can I get the same result with Java? I set the time zone to [CEST](http://www.timeanddate.com/library/abbreviations/timezones/eu/cest.html) since it seems to be what Ruby works with. So I tried this:

```java
GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("CEST"));
calendar.set(2014, 9, 5);
System.out.println("" + calendar.getTimeInMillis());
// Returns: 1412498241422

```

Answer: 
There are three problems with your current code:

* "CEST" isn't a time zone Java recognized. Try `Europe/Paris` instead, as a European time zone
* `java.util.Calendar` uses 0-based months (yes, it's awful)
* You haven't cleared out the time part of the `Calendar`, so it'll give you the current time of day, on that date

This works:

```
import java.util.*;

public class Test {
    public static void main(String[] args) throws Exception {
        TimeZone zone = TimeZone.getTimeZone("Europe/Paris");
        Calendar calendar = new GregorianCalendar(zone);
        // Month 8 = September in 0-based month numbering
        calendar.set(2014, 8, 5, 0, 0, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        System.out.println(calendar.getTimeInMillis());
    }
}

```

If you *know* the month in advance, you can use the constants instead:

```
calendar.set(2014, Calendar.SEPTEMBER, 5, 0, 0, 0);

```

If you can possibly move to using [Joda Time](http://joda.org/joda-time) or `java.time` from Java 8, however, those are much cleaner APIs.

For example, in Joda Time:

```
import org.joda.time.*;

class Test {
    public static void main(String[] args) {
        DateTimeZone zone = DateTimeZone.forID("Europe/Paris");
        // Look ma, a sensible month numbering system!
        LocalDate date = new LocalDate(2014, 9, 5);
        DateTime zoned = date.toDateTimeAtStartOfDay(zone);
        System.out.println(zoned.getMillis());
    }
}

```
You can use `System.currentTimeMillis()` to get the time in milliseconds since start of epoch.

If you want to translate to the same baseline as Ruby is using, that will be as simple as adding some fixed offset (i.e., use `System.currentTimeMillis() + DELTA`). You should be able to calculate `DELTA` by trying it in Ruby and in Java on some fixed date to see what the difference is.

Are you sure that Ruby's calculation isn't locale-dependent, though? It would be odd (not to say barely plausible) if it routinely used CEST.