There are several plugins that can do this. 

Whith my plugin [Stamp][1], you can add a timestamp to the filename or path in the following styles:

    <script src="/assets/build/js/1399647655/scripts.js"></script>
    <script src="/assets/build/js/scripts.1399647655.js"></script>
    <script src="/assets/build/js/scripts.js?ts=1399647655"></script>

The last one, which is the one you're looking for is made with:

    <script src="{{ craft.stamp.er('/assets/build/js/scripts.js', 'query') }}"></script> 

You can also get only the timestamp, and use it however you want, like this:

    {% set timestamp = craft.stamp.er('/assets/build/js/scripts.js', 'tsonly') %} 



  [1]: https://github.com/aelvan/Stamp-Craft