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: 
*java.time*
===========

The `java.util` Date-Time API and their formatting API, `SimpleDateFormat` are outdated and error-prone. It is recommended to stop using them completely and switch to the [modern Date-Time API](https://www.oracle.com/technical-resources/articles/java/jf14-Date-Time.html)\*, released in March 2014.

Also, quoted below is a notice at the [Home Page of Joda-Time](https://www.joda.org/joda-time/):

> 
> Note that from Java SE 8 onwards, users are asked to migrate to java.time (JSR-310) - a core part of the JDK which replaces this project.
> 
> 
> 

**Solution using `java.time`, the modern Date-Time API:**

```
import java.time.LocalDate;
import java.time.ZoneId;

public class Main {
    public static void main(String[] args) {    

        long millis = LocalDate.of(2014, 9, 5)
                                .atStartOfDay(ZoneId.of("Europe/Paris"))
                                .toInstant()
                                .toEpochMilli();

        System.out.println(millis);
    }
}

```

**Output:**

```
1409868000000

```

[`ONLINE DEMO`](https://ideone.com/c39t6w)

Avoid using two/three/four letter abbreviation for timezone name. Use the convention Region/City e.g. `Europe/Paris`. You can get the list of timezone names using [`ZoneId.getAvailableZoneIds()`](https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html#getAvailableZoneIds--).

Learn more about the modern Date-Time API from **[Trail: Date Time](https://docs.oracle.com/javase/tutorial/datetime/index.html)**.

---

\* For any reason, if you have to stick to Java 6 or Java 7, you can use [***ThreeTen-Backport***](http://www.threeten.org/threetenbp/) which backports most of the *java.time* functionality to Java 6 & 7. If you are working for an Android project and your Android API level is still not compliant with Java-8, check [Java 8+ APIs available through desugaring](https://developer.android.com/studio/write/java8-support-table) and [How to use ThreeTenABP in Android Project](https://stackoverflow.com/questions/38922754/how-to-use-threetenabp-in-android-project).
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.