简体   繁体   English

如何在Java中创建一个uuid参数来保存ntp time的值

[英]how to create a uuid parameter in java which holds the value of ntp time

I have to create a parameter of type uuid, but here the problem is this uuid parameter should hold the value of combination of ntp time and integer values 我必须创建一个uuid类型的参数,但是这里的问题是这个uuid参数应该包含ntp timeinteger数值的组合值

import org.apache.commons.net.ntp.TimeStamp;
import java.util.*;

public class NtpTest {

public static void main(String[] args) {
    Integer value = new Integer(8);
    TimeStamp ntp = TimeStamp.getCurrentTime();
    // Here I have to create a UUID parameter by combining these value and ntp 
   // I tried with fllowing but got Invalid UUID string error
    UUID uid = UUID.fromString(value+ntp.toString()); 
}

Didn't get exact solution but tried some research, finally found converting ntp timestamp to UUID 没有得到确切的解决方案,但是尝试了一些研究,最终发现将ntp timestamp转换为UUID

import java.util.*;

import org.apache.commons.net.ntp.TimeStamp;

public class NtpToUuid {

public static void main(String[] args) {
    TimeStamp t2 = TimeStamp.getCurrentTime();
    UUID uuid3 = com.datastax.driver.core.utils.UUIDs.startOf(t2.getTime());
    System.out.println("UUID3 : "+uuid3);
        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM