Get local Date as long in android, confusion maybe?

I might have little confusion about Date in android/java. What I know is when calling new Date() it creates a Date instance with current UTC date and time, Right ? Because Date in java don't have any time zone thing, So if I call new Date().getTime() I will get a long value(time stamp) as UTC, not as local time, right ?

And to show date, we use 'DateFormat' and it has time zone info. So when I call DateFormat.getDateTimeInstance().format(new Date()) I will get a string with local time.

But how do I get long value(time stamp) of local time ?? I found this answer but is that the only way ? or something more simple ?

Thank you :)

Jon Skeet
people
quotationmark

So if I call new Date().getTime() I will get a long value(time stamp) as UTC, not as local time, right?

Well, it will give you the number of milliseconds since Jan 1st 1970 00:00:00 UTC, yes. It's not "in" UTC particularly; it's just a number of milliseconds since an arbitrary epoch.

But how do I get long value(time stamp) of local time?

You don't, basically. That turns out not to be a particularly useful concept. If you think about it, a timestamp is just an instant in time - it's independent of time zones. You can express the Unix epoch in any time zone; it just happens to normally be expressed in terms of UTC.

If you need the local date/time for a particular timestamp, you just need to remember the timestamp itself and the relevant time zone. If you give us more information about what you're trying to achieve, we may be able to help more.

people

See more on this question at Stackoverflow