1

I use Omnet++-4.6 and Veins-4a2.

The method simTime() returns the current time in seconds. I need to transform it to milliseconds, but I could not.

When I declare a simtime_t variable like this:

simtime_t TimeVar = simTime() * 1000;

it gives an error. Do you have an idea on how can I do this?

pys
  • 198
  • 1
  • 6
Fariha
  • 497
  • 1
  • 5
  • 13
  • Your question in very hard to answer. A lot of helpful tips on how to best phrase a question can be found on http://stackoverflow.com/help/how-to-ask – Christoph Sommer Feb 23 '17 at 10:19

2 Answers2

3

simtime_t is a class for storing the simulation time in seconds with different levels of precision as explained in the manual https://omnetpp.org/doc/omnetpp/manual/#sec:simple-modules:simulation-time

If you need milliseconds, do the following:

double ms = simTime().dbl() * 1000;

But take into account that if you want to use this value for scheduling other message, you have to convert this time again to seconds to be coherent with the simulation time:

scheduleAt(ms / 1e3, msg);

pys
  • 198
  • 1
  • 6
  • 3
    Note that using a `double` to represent time is fraught with danger. Time stamps are routinely added, subtracted, compared in programs. For more details and examples, see http://stackoverflow.com/q/588004 – Christoph Sommer Feb 23 '17 at 11:12
  • Thank you for your response, it works. I need to convert the simTime() just for my log fie and in all simulation I used simTime() in seconds. – Fariha Feb 23 '17 at 13:05
1

Another but more complicated way would be to use the SimTime class to store your simulation times in. You can use the inUnit method to get the value as a representation of the desired unit.

Julian Heinovski
  • 1,822
  • 3
  • 16
  • 27