开发者

Time stamp with milliseconds, calculating "delay"

When i create an instance of an object, say, Message m i want to set a field in it, a time stamp.

Nothing to do with databases.

When this object is passed around it will have its time stamp eventually read and compared to the current time of its recipient to calculate de开发者_JAVA百科lay = timeNow - m.SENT_AT. Both objects exist on the same system and both entities use the system's clock (actual time, nothing fancy, the delay is important), but I want this in milliseconds.


Something like this:

class Message {
    public final long sentAt; 
    public final String data;

    public Message(String data) {
        this.sentAt = System.currentTimeMillis()
        this.data = data;
    }

    public long timeSinceSent() {
        return System.currentTimeMillis() - sentAt;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜