通过函数将当前日期转换为unix时间戳:android

通过函数将当前日期转换为unix时间戳:android,android,timestamp,Android,Timestamp,我有一个简单的日历功能,可以获取当前日期和时间。在将日期作为json传递之前,我想将其转换为unix时间戳格式 我的代码: SimpleDateFormat s = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); final String format = s.format(new Date()); 答案很简单,只需添加一行并在发送json的地方添加“unixTime” long unixTime = System.cu

我有一个简单的日历功能,可以获取当前日期和时间。在将日期作为json传递之前,我想将其转换为unix时间戳格式

我的代码:

SimpleDateFormat s = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
                final String format = s.format(new Date());

答案很简单,只需添加一行并在发送json的地方添加“unixTime”

long unixTime = System.currentTimeMillis() / 1000L;

谢谢你的帮助,可能是重复的,问题解决了。