0
votes

I am having the time-stamped value in nanoseconds for example, 1126732882247990. I am trying to convert into standard utc format but I am not able to convert it as most of the functions for standard utc conversion in MATLAB are limited to microsecond value.

Can someone of you help me to figure out the conversion in MATLAB.

1
why is it so important to use UTC format AND keep nanosecond resolution? why not separate this into two variables, one will be integer seconds (->UTC) and the other will be the nanosecond fraction that was left?user2212608
Sorry Robocop, could you please clarify your point. I am not getting itRockStar

1 Answers

1
votes

First of all, you don't have nanoseconds as you seem to believe.

The date 1126732882247990 can be decomposed as follows :

1126732882247990 microseconds

1126732882247 milliseconds

1126732882 seconds.

So, If you need a milliseconds precision it is quite simple:

  // keep only the milliseconds 
  long date = Long.parseLong("1126732882247990".substring(0,13));

2005-09-14 23:21:22.247

  // then apply whatever conversion you want
  DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
  df.setTimeZone(TimeZone.getTimeZone("France"));

2005-09-14 09:21:22.247

If the only finality is to display it, you also can add the microseconds:

 String timeStamp = df.format(dateObj).concat(".").concat("1126732882247990".substring(13,16));

2005-09-14 09:21:22.247.990