转自:https://www.cnblogs.com/guolongzheng/p/9399414.html 

时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。通俗的讲, 时间戳是一份能够表示一份数据在一个特定时间点已经存在的完整的可验证的数据。 它的提出主要是为用户提供一份电子证据, 以证明用户的某些数据的产生时间。 在实际应用上, 它可以使用在包括电子商务、 金融活动的各个方面, 尤其可以用来支撑公开密钥基础设施的 “不可否认” 服务。

有时候我们模拟网络发包请求的时候,POST,GET的某个参数就是需要带上当前时间的时间戳。

如下简单的实现了下

  1. #include <time.h>
  2. #include <sys/timeb.h>
  3. /*C++版本获取时间戳13位*/
  4. long long getTimeStamp()
  5. {
  6.     timeb t;
  7.     ftime(&t);
  8.     return t.time * 1000 + t.millitm;
  9. }
  10. /*C语言版本获取时间戳13位*/
  11. long long getSystemTime() {

  12.     time_t tl;
  13.     tl = time(NULL);
  14.     srand(time(NULL));
  15.     int millitm = 0;
  16.     char buf[3] = { 0 };
  17.     char soucres[20] = { 0 };
  18.     for (int i = 0; i < 3; i++)
  19.         strcat_s(soucres, itoa(rand() % 10, buf, 10));
  20.     millitm = atoi(soucres);
  21.     return tl * 1000 + millitm;
  22. }

09-05 02:02
查看更多