Getting time and date on a file name

Discussion in 'JavaScript' started by chrisj, May 1, 2012.

  1. #1
    This javascript which I'm using works with a webcam to record a video.

    The end result, after the file is recorded generates a file name, as you can see from the code below: Video+video_id.

    I recorded a file today April 30th, and the file was named: Video1335806296490.flv. I don't understand where the time and date are in this file name, and I don't understand why all the recorded files begin with 1335. Can you shed some light here?

    (Or suggest an alternative tweak to make file names more recognizable?)

    Thanks.








    <script type="text/javascript">
    var video_id = get_id();
    var filename = get_parm('filename');
    if(filename == '' || filename == null)
    {
    filename = 'Video'+video_id;
    }

    var flashvars = {
    filename: filename,
    rtmpPath: "rtmp://xxxxxxxxxxxxxxx",
    finishURL: "videoplayer.htm?filename="+filename,
    };
    var params = {
    menu: "false",
    scale: "noScale",
    allowScriptAccess: "always",
    bgcolor: "#000000"
    };
    var attributes = {
    id:"webcamrecording"
    };
    swfobject.embedSWF("recording.swf", "recording", "620", "470", "9", "expressInstall.swf", flashvars, params, attributes);

    function get_id()
    {
    var newDate = new Date();
    return newDate.getTime();
    }

    function get_parm(name)
    {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
    {
    return "";
    }
    else
    {
    return results[1];
    }
    }

    </script>
     
    chrisj, May 1, 2012 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Those numbers in the file name are the date and time expressed as seconds since the epoch. Search on "JavaScript Date object" and you'll see how it works.
     
    rainborick, May 1, 2012 IP
  3. chrisj

    chrisj Well-Known Member

    Messages:
    606
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Thanks for the explanation.
    I searched a bit on date object, as suggested, but I'm not skilled in JavaScript.

    Would there be an easy line or two of code that I could add so as when I see the file name generated, it would be easier to determine when the file name is created, as in some type of easy to read month and day and year and time of day?

    Any assistance will be greatly appreciated. Thanks
     
    chrisj, May 29, 2012 IP