I am writing an application that stores a series of values in an Array List object. All of the values are stored as Strings in the array, and one of the parameters is a time stamp which is prefixed with "Timestamp: " followed by the actual Unix timestamp (e.g. 1556849753564)
I need to parse only the Unix timestamp from the Timestamp String object.
Here is what I have tried:
public void parseTimestamp() {
String lastBlockTimeAsString = (String) HashArray.hashArray.get(HashArray.hashArray.size() - 12);
char[] timeAsCharArray = lastBlockTimeAsString.toCharArray();
long lastBlockTime = Long.parseLong(String.valueOf(timeAsCharArray[12] + timeAsCharArray[13] ..... etc ));
}
The HashArray.hashArray.get() call is just pulling the Timestamp object from the Array List. I am pulling the 12th character from the array because that is the start of the timestamp.
In Python I could do something like:
timeAsCharArray[12]:[24]
How can I accomplish this in Java more elegantly than the solution I came up with, which is basically to concatenate each individual character from the array.. Any help would be appreciated!
String timeStampString = "Timestamp: 1556849753564"; String strgTime = timeStampString.split(":\\s+")[1].trim(); long lastBlockTime = Long.parseLong(strgTime);?