最近,写了一个ustime函数,不小心搞出了一个bug, 查了一下,修复了。
然后,我想,这函数应该很常见啊,于是在开源代码中搜了一下,果然有,来看看别人咋写:
- /* Return the UNIX time in microseconds */
- long long ustime(void) {
- struct timeval tv;
- long long ust;
-
- gettimeofday(&tv, NULL);
- ust = ((long long)tv.tv_sec)*1000000;
- ust += tv.tv_usec;
- return ust;
- }
-
- /* Return the UNIX time in milliseconds */
- mstime_t mstime(void) {
- return ustime()/1000;
- }
经测试, OK, 这样清晰多了。







![[手游] 三网H5小游戏【少年仙路】WIN系服务端+Linux手工服务端+详细搭建教程](https://cdn.jxasp.com:9143/image/20260615/136BC33AA47EB0D84E878835A8B38FDB.png)











