1

I downloaded Java Native Access in Eclipse for use in a program, specifically to use a variable time_t date in order to get a unix timestamp. Does that structure exist, or is it in another form?

In case it doesn't exist, what would be my best alternative to get time to just use System.currentTimeMillis()?

zx485
  • 28,498
  • 28
  • 50
  • 59
Alpha1126
  • 11
  • 1
  • What native functions are you trying to use? That has a large bearing on the "best" way to get unix epoch time and what type to use to represent it. – technomage Jan 20 '17 at 19:25

1 Answers1

0

JNA does not have a specific type for time_t because it's usually easily modeled on any particular operating system by an existing primitive type.

You can define one yourself easily... on macOS you could just replace it with a NativeLong or use:

class time_t extends IntegerType { 
    public time_t() { 
        super(Native.LONG_SIZE); 
    } 
} 

Since time_t is defined in seconds, you could use System.currentTimeMillis() if you divided it by 1000. It all depends on what use you have for the variable. Generally if you're using JNA you're trying to use some native time value.

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63