> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man9/microtime.9.md).

# microtime.9

`bintime` — 获取当前时间

## 名称

`bintime`, `getbintime`, `microtime`, `getmicrotime`, `nanotime`, `getnanotime`

## 概要

```c
#include <sys/time.h>
```

```c
void
bintime(struct bintime *bt)

void
getbintime(struct bintime *bt)

void
microtime(struct timeval *tv)

void
getmicrotime(struct timeval *tv)

void
nanotime(struct timespec *ts)

void
getnanotime(struct timespec *tsp)
```

## 描述

`bintime` 和 `getbintime` 函数将系统时间以 `struct bintime` 的形式存储在 `bt` 所指定的地址处。`microtime` 和 `getmicrotime` 函数执行相同的功能，但将时间记录为 `struct timeval`。类似地，`nanotime` 和 `getnanotime` 函数将时间存储为 `struct timespec`。

`bintime`、`microtime` 和 `nanotime` 函数总是查询 timecounter 以尽可能精确地返回当前时间。而 `getbintime`、`getmicrotime` 和 `getnanotime` 函数是抽象层，返回精度较低但获取速度更快的时间。

`getbintime`、`getmicrotime` 和 `getnanotime` 函数的设计意图是在定时器精度与执行时间之间贯彻用户的偏好。

## 参见

binuptime(9), getbinuptime(9), getmicrouptime(9), getnanouptime(9), [microuptime(9)](/man/man9/microuptime.9.md), nanouptime(9), [tvtohz(9)](/man/man9/tvtohz.9.md)

## 历史

`bintime` 函数首次出现于 FreeBSD 5.0。`microtime` 和 `nanotime` 函数首次出现于 FreeBSD 3.0，但自 4.4BSD 起就以其他形式存在。

## 作者

本手册页由 Kelly Yancey <kbyanc@posi.net> 编写。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man9/microtime.9.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
