The Google Maps JS API has a traffic level .
You need to add the traffic level to the map:
var trafficLayer = new google.maps.TrafficLayer(); trafficLayer.setMap(map);
There is a living example.
And if you want to calculate the duration, the distance API from Google and in this question from Stackoverflow you can see the answer.
In the Direction Service you need to specify this field:
{ origin: LatLng | String, destination: LatLng | String, travelMode: TravelMode, transitOptions: TransitOptions, unitSystem: UnitSystem, durationInTraffic: Boolean, waypoints[]: DirectionsWaypoint, optimizeWaypoints: Boolean, provideRouteAlternatives: Boolean, avoidHighways: Boolean, avoidTolls: Boolean region: String }
You can try the traffic first and save the duration, and then you can close the traffic option and save it. So you can see the difference between the two.
source share