My requirement:
I get value in EpochMillis
public void Method(){
//long val = epoch time in millis
//Format the (val)epochtime in MMddHHmmss and set ZoneOffset.UTC
//long formattedTime = formatted time;
obj.setTime(formattedTime);
}
The final objective is to get the formatted time in the above mentioned format and result should be in "long" type
I can process the expected data, but results in String, while converting back to Long, leading zeros are lost. (i want to retain the length as 10 - as per the format)
Can someone help ?
I tried below
final long timeInMillis = Instant.now().toEpochMilli();`
final Instant instant = Instant.ofEpochMilli(Long.valueOf(timeInMillis));`
final String formattedDate = DateTimeFormatter.ofPattern("MMddHHmmss").withZone(ZoneOffset.UTC).format(instant);
Here I could get only String, I expect long which is formatted (10 in length)
Edit1: Or I need any other idea. I need to set the time like 0803072816 [MM-dd-HH-mm-ss] using Setter Method which accepts only Long value. Long in milliseconds without formatting also fine either formatter long value or unformatted time in milliseconds, in both cases length should be exactly = 10