Find time elapsed since the start of workflow execution

Hi,

I have a use case where based on a particular timeout period, I need to decide if the last activity of the workflow needs to be invoked or not. So, is there any way to see how much time has elapsed since workflow execution started, and based on that I decide whether to invoke that activity or not in my workflow code.

Let me know if there is any other way also to solve the same.

@tihomir Please guide.

is there any way to see how much time has elapsed since workflow execution started

To get current workflow time (inside workflow code) you can use
Workflow.currentTimeMillis()
To get the time when workflow run was started (client requested start and server created it) you can use
Workflow.getInfo().getRunStartedTimestampMillis()

So depends on what you mean by “workflow execution started”
if you mean time since exec was created on server (not the time when your worker picked up workflow task and started execution) you can:

long timeSinceStarted = Workflow.currentTimeMillis() - Workflow.getInfo().getRunStartedTimestampMillis();

If you want to know the elapsed time since your worker started executing your workflow method store
Workflow.currentTimeMillis() as first line of your workflow method code, then later on
call Workflow.currentTimeMillis() again and compare the two.