获取时间戳的方法取决于您正在使用的编程语言。下面是一些常见编程语言如何获取时间戳的示例:
1.Python:
pythonimport time timestamp = time.time() print(timestamp)
2.JavaScript (Node.js):
javascriptconst timestamp = Date.now(); console.log(timestamp);
3.Java:
javaimport java.util.Date; public class Main { public static void main(String[] args) { long timestamp = new Date().getTime(); System.out.println(timestamp); } }
4.C++ (需要包含和头文件):
c++#include <chrono> #include <ctime> #include <iostream> int main() { auto now = std::chrono::system_clock::now(); std::time_t now_time = std::chrono::system_clock::to_time_t(now); std::cout << now_time << std::endl; return 0; }
5.C#:
csharpusing System; public class Program { public static void Main() { long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); Console.WriteLine(timestamp); } }
6.PHP:
php<?php $timestamp = time(); echo $timestamp; ?>
7.Ruby:
rubytimestamp = Time.now.to_i puts timestamp