How do I capture build time at the end of a build?

I am using the gradle.buildFinished hook to capture various metrics at the end of a gradle build is it possible to capture the total time?

Simplified example:

gradle.buildFinished { buildResult ->
 println "Tasks: " + tasks
 println "Version: " + version
 println "Plugins: " + plugins
 println "Total time: " + time

Obviously time isnt a gradle project property, but i’m not sure how to get the total time.

You can use ‘gradle.buildStarted’ together with ‘gradle.buildFinished’ to get the total time.

Can you provide a quick snippet for this? I tried using gradle.buildStarted but couldnt get it to invoke I read the post regarding this and the use of the Gradle.addBuildListener but still come up empty.