Unix时间戳(英文为Unix epoch, Unix time, POSIX time 或 Unix timestamp)
是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒。
UNIX时间戳的0按照ISO 8601规范为 :1970-01-01T00:00:00Z
一个小时表示为UNIX时间戳格式为:3600秒;一天表示为UNIX时间戳为86400秒,闰秒不计算。
在大多数的UNIX系统中UNIX时间戳存储为32位,这样会引发2038年问题或Y2038。
时间戳就是如1377216000000 这种格式我们在mysql数据库中会经常用到把时间转换成时间戳或把时间戳转换成日期格式了,下面我来介绍安卓中时间戳 *** 作转换方法。
一、原理
时间戳的原理是把时间格式转为十进制格式,这样就方便时间的计算。好~ 直接进入主题。(下面封装了一个类,有需要的同学可以参考或是直接Copy 就可以用了。)
如: 2013年08月23日 转化后是 1377216000000
二、步骤
1、创建 DateUtilsl类。
代码如下 复制代码
importjavatextParseException;
importjavatextSimpleDateFormat;
importjavautilDate;
/
@author Msquirrel
/
public class DateUtils {
privateSimpleDateFormat sf = null;
/获取系统时间 格式为:"yyyy/MM/dd "/
public static String getCurrentDate() {
Date d = newDate();
sf = newSimpleDateFormat("yyyy年MM月dd日");
returnsfformat(d);
}
/时间戳转换成字符窜/
public static String getDateToString(long time) {
Date d = newDate(time);
sf = newSimpleDateFormat("yyyy年MM月dd日");
returnsfformat(d);
}
/将字符串转为时间戳/
public static long getStringToDate(String time) {
sdf = newSimpleDateFormat("yyyy年MM月dd日");
Date date = newDate();
try{
date = sdfparse(time);
} catch(ParseException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
returndategetTime();
}
2、在对应使用的地方调用就可以了。
代码如下 复制代码
DateUtilsgetCurrentDate(); //获取系统当前时间
DateUtilsgetDateToString(时间戳); //时间戳转为时间格式
DateUtilsgetStringToDate("时间格式");//时间格式转为时间戳
下列函数可以返回当前时间的Unix的时间戳的是()
Adate()timezone()set()
Bdate
Cstrtotime()
Dtime()
正确答案:D
本文实例讲述了JavaScript输出当前时间Unix时间戳的方法。分享给大家供大家参考。具体如下:
下面的代码通过Date对象的getTime()放回unix时间戳,即从1970年1月1日到当前时间的秒数
<!DOCTYPE
html>
<html>
<body>
<p
id="demo">
Click
the
button
to
display
the
number
of
milliseconds
since
midnight,
January
1,
1970</p>
<button
onclick="myFunction()">Try
it</button>
<script>
function
myFunction()
{
var
d
=
new
Date();
var
x
=
documentgetElementById("demo");
xinnerHTML=dgetTime();
}
</script>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
unix时间戳是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒。 [1]
Unix时间戳(英文为Unix epoch, Unix time, POSIX time 或 Unix timestamp)
是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒。
UNIX时间戳的0按照ISO 8601规范为 :1970-01-01T00:00:00Z
一个小时表示为UNIX时间戳格式为:3600秒;一天表示为UNIX时间戳为86400秒,闰秒不计算。
以上就是关于什么是Unix时间戳全部的内容,包括:什么是Unix时间戳、怎么把Unix时间戳变成一般时间、下列函数可以返回当前时间的Unix的时间戳的是()等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)