I tested this code:
java.util.Date d=new java.util.Date();
System.out.println("date="+d);
The output is:
Sat May 09 02:48:42 CDT 2015
It has no milliseconds...
p.s lets say if to use Date
for ConcurrentLinkedHashMap<Date,String>
(wiki link) I can see the minimum date value is second :(
EDIT :
public class HashMapTest0 {
private ConcurrentMap<Date,Date> values=new ConcurrentLinkedHashMap.Builder<Date, Date>()
.maximumWeightedCapacity(1000)
.build();
public static void main(String [] args){new HashMapTest0();}
HashMapTest0(){
for(int i=0; i<10; i++){
Date d=new Date();
values.put(d, d);
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
for(Date d:values.values()){
String s=new SimpleDateFormat("dd-MM-yyyy:HH:mm:ss.sss").format(d)
.replaceAll("-", "_")
.replaceAll(":", "_");
System.out.println(s);
}
}
}
the output maybe something like this :
09_05_2015_04_07_10.010
09_05_2015_04_07_10.010
09_05_2015_04_07_10.010
09_05_2015_04_07_10.010
09_05_2015_04_07_10.010
09_05_2015_04_07_10.010
09_05_2015_04_07_10.010
09_05_2015_04_07_10.010
09_05_2015_04_07_10.010
09_05_2015_04_07_10.010
So my question is how to generate date with real time milliseconds, or is there is a more optimal way?