我一直在使用Processing 3.0,当我的Arduino输出某些值时,我正在尝试打印一个简单的时间戳,但它无效.我尝试使用SimpleDateFormat,但它总是返回1970.01.17 17:48:35 GMT,而不是实际时间.以下是MVCE:
void setup ()
{
SimpleDateFormat format = new SimpleDateFormat ("yyyy.MM.dd HH:mm:ss z");
format.setTimeZone (TimeZone.getDefault());
long timestamp = getTimeNow();
println(format.format(new Date(timestamp)));
println(timestamp);
}
long getTimeNow ()
{
Date d = new Date ();
Calendar cal = new GregorianCalendar();
long current = d.getTime()/1000;
long timezone = cal.get(Calendar.ZONE_OFFSET)/1000;
long daylight = cal.get(Calendar.DST_OFFSET)/1000;
return current + timezone + daylight;
}
Run Code Online (Sandbox Code Playgroud)
输出示例:
1970.01.17 17:48:35 GMT
1442915733
Run Code Online (Sandbox Code Playgroud)
我怀疑问题是什么getTimeNow(),因为,如果我将值插入在线纪元转换器,我得到正确的时间.上面的代码有什么问题?
1.)
long milli=24*60*60*1000;
long micro=24*60*60*1000*1000;
long result=micro/milli;
Run Code Online (Sandbox Code Playgroud)
结果应该是,1000但事实并非如此.
请告诉我输出并解释一下?
2)
int i=0;
for(a=0;a<=integer.MAX_VAL;a++)
{
i++;
}
S.O.P(i);
Run Code Online (Sandbox Code Playgroud)
通常它会进入infine循环,因为它有最大值它应该从循环中出来.在什么条件下它会成功执行,什么是例外价值......任何人都可以告诉我关于VM ...在JAVA中处理数字的问题