【问题标题】:How to get microsecond from now() in Erlang如何在 Erlang 中从 now() 获得微秒
【发布时间】:2020-06-14 11:34:33
【问题描述】:

我尝试将相应的线程与时间戳(从现在开始的微秒函数)匹配,就像 jill 从 john [739000] 收到介绍消息 并且 john 从 jill [739000 收到回复消息]

if
     I == true ->
         M_pid!{lists:concat([Self_name," received intro message from ", Process_name , "[",erlang:now(),"]"]), self()},
         %io:fwrite(I),
         whereis(Process_name)!{Self_name, "reply",self()},
         friends(Msg, M_pid, State + 1, Self_name);
     R == true ->
         M_pid!{lists:concat([Self_name," received reply message from ", Process_name , "[",pid_to_list(Process_id),"]"]), self()},
         friends(Msg, M_pid, State + 1, Self_name)
 end

我试图从process_id 更改为从now() 的微秒。 我是 Erlang 的新手。提前谢谢你们!

【问题讨论】:

    标签: multithreading erlang


    【解决方案1】:

    erlang:now() 已弃用,不应使用。有两个选项可以获取当前时间(以微秒为单位)

    1. os:timestamp()
    {Mega, Sec, Micro} = os:timestamp(),
    (Mega * 1000000 + Sec) * 1000000 + Micro.
    
    1. os:system_time(microseconds)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-11
      • 2011-10-04
      相关资源
      最近更新 更多