SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    calif
    Posts
    740
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting time and date on a file name

    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, and the file was named: Video1335806296490.flv. I understand that the time and date in this file name, is the time and day of the recording expressed in seconds.

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

    Any assistance will be greatly appreciated. (Or suggest an alternative tweak to make file names more recognizable?)

    Thanks.

    Code:
    <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>

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Here is a code that you can use in your script to get the date-time from "video_id" .
    Code:
    <script type="text/javascript"><!--
    // http://www.coursesweb.net/javascript/
    var video_id = 1335806296490;
    var date = new Date(video_id);
    var year = date.getFullYear();
    var month = date.getMonth() + 1;      // "+ 1" becouse the 1st month is 0
    var day = date.getDate();
    var hour = date.getHours();
    var minutes = date.getMinutes();
    var secconds = date.getSeconds()
    
    var seedatetime = month+ '.'+ day+ '.'+ year+ ' - '+ hour+ ':'+ minutes+ ':'+ secconds;
    
    alert(seedatetime);        // for test
    //-->
    </script>
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    calif
    Posts
    740
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that reply, however I don't know how to integrate that into the code in my posting.
    And i'm not sure why you have 1335806296490 in your script.
    Any additional clarification/enlightenment would be appreciated.

  4. #4
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    The number 1335806296490 is the value of the variable "video_id" from your script, I thogut, from this code:
    Code:
    filename = 'Video'+video_id;
    that variabe contains the number you want to transform in date-time.
    If you don't know how to integrate that code into your script, maybe it is needed to learn some JavaScript.
    That example shows you how to get the year, month, day, hour, ..., from a number of millisecconds.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  5. #5
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    calif
    Posts
    740
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the replies. I ended up adding this to the code:
    function get_id()
    {
    var newDate = new Date();
    return ' '+parseInt(newDate.getMonth()+1)+'-'+newDate.getDate()+'-'+newDate.getFullYear()+'-'+newDate.getTime()
    }

    My intention was to have a more informative file name when looking at the completed webcam video file list, and it is. But also, for some reason, the file name appears across the bottom of the video itself (briefly). By looking at the code that I had originally posted, can you suggest how I can keep the file name, but without it appearing on the video? Thanks

  6. #6
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also if you're looking for more information about split functions I put together some information on the topic and I think it could be relevant to you. http://www.verious.com/board/AKumar/...lit-functions/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •