Hi I'm new to Java, I'm trying to convert standard time to Unix time so I can use that data in Max/MSP (to modulate a tone) eventually I will allow this program to take a text file of ordinary times and write to a text file the converted Unix times but I've currently run into a problem, it all works fine but it seems to be off by an hour.

To test I tried converting the time 2010-10-26 10:25:33 and I got 1288049133.

Here is my code:

import java.util.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class timeToUnix2 {
   public static void main(String[] args) {
    String pattern = "yyyy-MM-dd hh:mm:ss";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
     Date now = format.parse("2010-10-26 10:25:33Z");
      long nowLong = now.getTime()/1000;
      System.out.println("Value is " + nowLong);
      catch (ParseException e) 

Please excuse the way I write code, I'm sure there is a more efficient way to do things but as I said I am learning.


6 Years
Discussion Span
Last Post by di2daer

Isn't this because of timezones? I think you might need to adjust.
Something like:

TimeZone tz = TimeZone.getDefault();
long gmtAdjust = tz.getDSTSavings()/1000;

But I'm not really sure though...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.