Unix 时间戳转换工具

2015-12-03

本页面仅用于个人学习使用,参考页面: chinaz unix timestamp tool

Unix时间戳(Unix timestamp) → 北京时间

获取现在的Unix时间戳(Unix timestamp)?

  1. Java time
  2. JavaScript Math.round(new Date().getTime()/1000) getTime() //返回数值的单位是毫秒
  3. Microsoft .NET / C# epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000
  4. MySQL SELECT unix_timestamp(now())
  5. Perl time
  6. PHP time()
  7. PostgreSQL SELECT extract(epoch FROM now())
  8. Python import time然后time.time()
  9. Ruby Time.now或`Time.newTime.now.to_i
  10. SQL Server SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
  11. Unix / Linux date +%s
  12. VBScript / ASP DateDiff("s", "01/01/1970 00:00:00", Now())
  13. 其他操作系统 (如果Perl被安装在系统中) 命令行状态下执行 perl -e "print time"

Unix时间戳(Unix timestamp) → 普通时间?

  1. Java String date = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date(Unix timestamp*1000))
  2. JavaScript 先 var unixTimestamp = new Date(timestamp * 1000),然后 commonTime = unixTimestamp.toLocaleString()
  3. Linux date -d @Unix timestamp
  4. MySQL from_unixtime(Unix timestamp)
  5. Perl, 先 my $time = Unix timestamp, 然后my ($sec, $min, $hour, $day, $month, $year) = (localtime($time))[0,1,2,3,4,5,6]
  6. PHP date('r', Unix timestamp)
  7. PostgreSQL SELECT TIMESTAMP WITH TIME ZONE 'epoch' + Unix timestamp) * INTERVAL '1 second';
  8. Python import time``time.gmtime(Unix timestamp)
  9. Ruby Time.at(Unix timestamp)
  10. SQL Server DATEADD(s, Unix timestamp, '1970-01-01 00:00:00')
  11. VBScript / ASP DateAdd("s", Unix timestamp, "01/01/1970 00:00:00")
  12. 其他操作系统, (如果Perl被安装在系统中) 命令行状态:perl -e "print scalar(localtime(Unix timestamp))"

普通时间 → Unix时间戳(Unix timestamp)?

  1. Java long epoch = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse("01/01/1970 01:00:00");
  2. JavaScript var commonTime = new Date(Date.UTC(year, month - 1, day, hour, minute, second))
  3. MySQL SELECT unix_timestamp(time)时间格式: YYYY-MM-DD HH:MM:SS 或 YYMMDD 或 YYYYMMDD
  4. Perl, 先 use Time::Local 然后 my $time = timelocal($sec, $min, $hour, $day, $month, $year);
  5. PHP mktime(hour, minute, second, month, day, year)
  6. PostgreSQL SELECT extract(epoch FROM date('YYYY-MM-DD HH:MM:SS'));
  7. Python, 先 import time 然后 int(time.mktime(time.strptime('YYYY-MM-DD HH:MM:SS', '%Y-%m-%d %H:%M:%S')))
  8. Ruby Time.local(year, month, day, hour, minute, second)
  9. SQL Server SELECT DATEDIFF(s, '1970-01-01 00:00:00', time)
  10. Unix / Linux date +%s -d"Jan 1, 1970 00:00:01"
  11. VBScript / ASP DateDiff("s", "01/01/1970 00:00:00", time)

关于内容(信息、资料、图像等)的转载

本网站所有内容仅供学习交流,均禁止转载至营利、非营利网站或内联网。如需帮助,请联系作者 admin#put.im。