Gettime()

I am trying to write a cookie with the current time in
milliseconds.
I can do this with a javascript as follows:
<script type="text/javascript" language="JavaScript">
var t = new Date();
var exp = '';
var beginmilliseconds = t.getTime();
document.cookie = 'timeonpage=' + escape(beginmilliseconds) +
'; path=/' + exp;
</script>
But I'd rather do this using the cold fusion cfcookie command
- but it has to be in the javascript time formula for milliseconds
(as I use another javascript to read and do calculations on the
cookie).
My problem is I don't know how to get the variable from
gettime() into cold fusion.
My understanding is that the gettime() javascript function
pulls milliseconds from 1970. I am not aware of any cold fusion
command that will reproduce the same results?
Any suggestions?
Thanks,
Bill

bmyers wrote:
> Any suggestions?
in mx, this should work:
<cffunction name="toEpoch" access="public" output="no"
returnType="numeric"
hint="converts datetime to java epoch offset">
<cfargument name="thisDate" required="Yes" hint="datetime
to convert to java
epoch" type="date">
<cfreturn arguments.thisDate.getTime()>
</cffunction>

Similar Messages

  • Help on getTimer() function = affects the main animation...

    Layers scenarios:
    Layer 1: pics animation
    Layer 2: text animation
    Layer 3: graph animation
    Layer 4: a movieclip()
    Here's goes, inside the movieclip on Layer 4 it is nested down to bubble movieclip which inside is an actionscript that animates the premade animation for the bubble just attaching those movieclips to an empty movieclip.
    The problem goes like this when I test the movie in the first maybe 5 or 10 seconds the animation seems just fine but after several seconds the animation becomes slower in the root timeline. It seems that getTimer() affects the animation, as far as I know getTimer() function returns the time the swf file begin playing in milliseconds. The code I was working on is based on the getTimer().
    What would be the work-around with this kind of scenario? I guess theres another function that works the same as getTimer that cannot affect my main animation.
    By the way, my animation on Layer 4 which is nested movieclip is a random bubbles with total of 200 instances.
    Thanks and more power to us all!

    Okay. Here is what I came up with. I'm not sure exactly what was in your timeline animated tweens. So perhaps this isn't what you wanted at all....
    All you need is the bubble artwork (set to export as "Bubble") and this code. It is full of "magic" numbers that I just fiddled with until I thought it looked pretty on my machine.
    Some important bits are the part where when the bubble gets off the top of the screen it removes itself.
    var home:MovieClip = this;
    var counter:Number=0;
    var totalBubbles:Number=200;
    clearInterval(bubbleIntervalID);
    var bubbleIntervalID=setInterval(attachBubble,150);
    function attachBubble() {
    var curBub:MovieClip = home.attachMovie("Bubble", "bubble", 1000+counter);
    curBub.blendMode = "hardlight";
    curBub._y = Stage.height + 100;
    curBub._x = (Stage.width - 50) * Math.random() + 50;
    curBub._xscale = curBub._yscale = Math.random() * 60 + 40;
    curBub._alpha = Math.random() * 80 + 20;
    curBub.vy=-(Math.random()*5+1)
    curBub.ay=-Math.random()/30
    curBub.x0=curBub._x;
    curBub.var1=Math.random()*100;
    curBub.var2=Math.random()*300;
    curBub.factor1=Math.random()/100;
    curBub.factor2=Math.random()/200;
    curBub.onEnterFrame = floatUp;
    counter++
    if(counter>totalBubbles){
      clearInterval(bubbleIntervalID);
    function floatUp() {
    this.vy += this.ay;
    this._y += this.vy;
    this._x = this.x0+this.var1*Math.sin(this._y*this.factor1)+this.var2*Math.sin(this._y*this.factor2) ;
    if(this._y<(-this._height)){
      delete this.onEnterFrame;
      this.removeMovieClip()

  • Using getTimer() as a Cache Killer

    Hi All,
    I have recently been working on a Flash file that dynamically loads a movie based on the contents of a simple XML file. I was concerned about caching issues so tried to set up the code to avoid the XML file being cached causing the wrong content to be loaded. I did this by adding a dummy query string to the file link which is a numerical value generated by getTimer().
    In practice the system mostly worked but occasionally old content would load even though the XML had been changed. The code runs a setInterval that checks the XML every 20 seconds and checks if the loaded file specfied has changed. The code loads the XML with the following code:
    holderXML.load("http://www.mysite/myscripts/myxml.xml?cachekill="+getTimer());
    The getTimer() functions starts counting in milliseconds as soon as the movie runs so there is a chance that the same query string is assigned to more than one file, meaning that an old cached version is loaded instead of the new, live file. I am now thinking about ways to improve this code and generate unique values for the query string. I thought using the epoch time - the time in milliseconds from which Flash calculates time and dates which is set to Jan 01 1970 - would generate a new value every millisecond and maybe adding an additional random number to that value to further reduce the chance of the same query string being generated more than once.
    this.onEnterFrame = function () {
    var nowDate:Date = new Date();
    nowTime = nowDate.getTime();
    randomNum = Math.round(Math.random()*10000);
    holderXML.load("http://www.mysite/myscripts/myxml.xml?cachekill="+nowTime+"rnd"+randomNum);
    Is there a better way of avoiding cache issues in Flash? Any comments and advice would be appreciated.

    Using anything that won't be the same value twice is sufficient.  Using Date.getTime() should work by itself.  Using Math.random() by itself is usually sufficient as well.

  • Calander getTime() display problems...

    I'm connected to an oracle database and there is a date_reception column that has the time in miliseconds: 992023833 which is 06/08/2001 2:12:34 PM.
    When try to get that same number fromm java I get a long integer that is: 992023954881 which is longer and a little different.
    Calendar c = Calendar.getInstance();
    c.set(2001, Calendar.JUNE, 8, 14, 12, 34);
    long bigtime = c.getTime().getTime();
    %><h3><%=bigtime%></h3>
    I need the same exact long integer as the oracle database one so I can run queries from that date...
    Please help...

    The Java number is time in milliseconds since midnight GMT on January 1, 1970. It appears that the Oracle number is the time in seconds; the remaining discrepancy is probably due to your time zone not being GMT.

  • Calender.getTime is displaying wrong date(One day earlier then the current)

    I am trying to display date from a calender object. My code is
    <h:outputText value="#{documentActivity.createdDate.time}" />
    createdDate is a calender object.
    this output is wrong, if the date is 05/28/07, this displays as 05/27/07.
    When I try to print the same from a java class it prints fine...
    createdDate.getTime().
    Has anyone faced this issue, Is there a problem with the JSF tag?

    Which JSF version? Do you use a converter?
    I can't reproduce it here in 1.2_04 with the following basic snippets:<h:outputText value="#{myBean.date}" /><br>
    <h:outputText value="#{myBean.calendar.time}" /><br>
    <h:outputText value="#{myBean.date}"><f:convertDateTime/></h:outputText><br>
    <h:outputText value="#{myBean.calendar.time}"><f:convertDateTime/></h:outputText><br>MyBeanpublic Date getDate() {
        return new Date();
    public Calendar getCalendar() {
        return Calendar.getInstance();
    }It all shows valid dates.

  • Adding time issue using Date's getTime method

    The following code is incorrectly adding 5 hours to the resultant time.
    I need to be able to add dates, and this just isn't working right.
    Is this a bug or am I missing something?
    long msecSum = 0 ;
    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS") ;
    try
    Date date1 = dateFormat.parse("01:02:05.101") ;
    Date date2 = dateFormat.parse("02:03:10.102") ;
    System.out.println("Date1: " + dateFormat.format(date1));
    System.out.println("Date2: " + dateFormat.format(date2));
    msecSum = date1.getTime() + date2.getTime() ; // adds 5 hours !!!
    System.out.println("Sum: " + dateFormat.format(msecSum)) ;
    catch (Exception e)
    System.out.println("Unable to process time values");
    Results:
    Date1: 01:02:05.101
    Date2: 02:03:10.102
    Sum: 08:05:15.203 // should be 3 hours, not 8

    Dates shouldn't be added, but if you promise not to tell anyone:
    long msecSum = 0 ;
    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS") ;
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    try
    Date date1 = dateFormat.parse("01:02:05.101") ;
    Date date2 = dateFormat.parse("02:03:10.102") ;
    System.out.println("Date1: " + dateFormat.format(date1));
    System.out.println("Date2: " + dateFormat.format(date2));
    msecSum = date1.getTime() + date2.getTime() ; // adds 5 hours !!!
    System.out.println("Sum: " + dateFormat.format(msecSum)) ;
    catch (Exception e)
    System.out.println("Unable to process time values");Me? I would just parse the String "01:02:05.101" to extract hours,
    minutes, seconds and milliseconds and do the math.

  • Date.getTime() with very early Dates

    Hi,
    I has a problem with Date.getTime(). If I want the milliseconds from an very early date (like 01.01.1970 00:01:00) I get an negative value from Date.getTime() (in this case -354000). I need this because I want to add a short time (not really date) to a date.
    I has played with different Timezone settings but this doesnt help.
    Has anyone an idea?
    Thank you.
    Bye

    Hmmm, I spotted that there was something wierd like this a few days ago. Consider the following:
    import java.text.*;
    import java.util.*;
    public class Test {
        public static void main(String[] argv)
                throws Exception {
            String dateFormat = "dd.MM.yyyy HH:mm:ss";
            String dateString = "01.01.1970 00:00:00";
            DateFormat df = new SimpleDateFormat(dateFormat);
            Date date = df.parse(dateString);
            System.out.println(date);
            System.out.println(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date));
            System.out.println(date.getTime());      
            System.out.println();
            Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            cal.setTime(date);
            System.out.println(cal.getTime());
            System.out.println(cal.getTimeInMillis());
            System.out.println();
            Date date2 = new Date(0);
            System.out.println(date2);
            System.out.println(date2.getTime());             
    }The output is:
    Thu Jan 01 00:00:00 GMT 1970
    01 January 1970 00:00:00 GMT
    -3600000
    Thu Jan 01 00:00:00 GMT 1970
    -3600000
    Thu Jan 01 01:00:00 GMT 1970
    0I get the same results using both IBM and Sun JVMs.
    Any ideas?

  • Problems with getTime().getTime() in Calender

    Hi!
    I'm trying to make some calculations involving dates from a data base. The database stores the dates as UTC, while my application runs on GMT + 1.
    I try to use a Calender and a TimeZone to convert from UTC, doing somehting like this:
                        Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
                        Calendar cal2 = Calendar.getInstance(); //My time zone is GMT + 1
                        long cal1Time = cal1.getTime().getTime();
                        long cal2Time = cal2.getTime().getTime();
                        System.out.println("cal1Time: " + cal1Time);
                        System.out.println("cal2Time: " + cal2Time);
                        System.out.println("cal1Hour: " + cal1.get(Calendar.HOUR_OF_DAY));
                        System.out.println("cal2Hour: " + cal2.get(Calendar.HOUR_OF_DAY));will print this:
    cal1Time: 1106751541814
    cal2Time: 1106751541814
    cal1Hour: 14
    cal2Hour: 15
    What happens here? Why does cal1.getTime() and cal2.getTime() show the same date while the get(Calender.HOUR_OF_DAY) seems to get it right?
    Thankfull for any help,
    David

    Let's assume you are in England and I am in Switzerland.
    A a given time, our watches won't display the same hour.
    Quite logical, isn't it?

  • GetTime Or Wait problem

    Hi..
    Time difference between two GetDate/Time calls with a wait function in between shows a lesser time taken than the wait duration specified. How is that possible? Pls see the attached VI. Any thoughts?
    Thanks and regards
    Chandra
    Attachments:
    GetTime Problem.vi ‏13 KB

    The get-date time function has a resolution of 16 ms. (or something like that) on Windows ,  the returned timestamp isn't fully accurate. This is an OS limitation.
    Ton (if you use the Tick count you will see a wait time of 50/51 ms)
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Anyway to get Date.getTime() to return back in seconds?

    according to javadocs, getTime() returns in miliseconds. I need it in seconds. Without doing any conversion to String and String manipulation, is there an easy way to get this to return in seconds to get it in seconds?

    just keeping u on your toes...Riiiiight. A response more like D'oh! would be more appropriate.

  • GetTimer

    I'm new to actionScript and I was trying to figure out how to
    use getTimer. My goal is to display my age in hours, minutes, or
    seconds. Or some combination of those.
    I found this but I think it does not apply to actionScript
    3.0
    this.onEnterFrame = function() {
    var time = new Date();
    var hours = time.getHours();
    var minutes = time.getMinutes();
    var seconds = time.getSeconds();
    How do I use getTimer in actionScript 3.0? I don't think that
    will be too hard but I am also unclear on how I would calculate my
    age based on the information I get from getTimer.
    Any Suggestions?

    create a date object with your birthdate, use the getTime()
    (NOT getTimer() ) method to obtain the number of milliseconds
    between your birth and 1970. then create another data object using
    the current date and use the getTime() method to determine the
    number of milliseconds between the current date and 1970. then
    subtract the current getTime() from your birth date getTime() and
    convert the resulting milliseconds (between the current date and
    your birthdate) to whatever format you want.

  • Object.Date times getTimes

    I have a problem with the Object Date, the recover data the database, getTimes() in my table I have a column with times, in a data I have 04:00:00 and recover with getTime() and convert in hours I get a result 3 hours, some solution

    Use java.util.Calendar
    Add 1 month to the day.
    Set the day of month to be 1.
    Subtract 1 day.
    Now you are on the last day of the month you wanted.

  • Timestamp.getTime() , Date.getTime()

    Hi,
    Is there a difference between Timestamp.getTime() and Date.getTime(). Are the returning values different for the same date?
    Olek

    Let's suppose, since we aren't told this, that you are asking about java.sql.Date and not about java.util.Date.
    You've read the documentation and learned that a Date object doesn't have a time component, correct? And that a Timestamp component does have one?
    If the Timestamp's time component is 00:00:00.000000 then I would expect its getTime() method to return the same as the getTime() method of a Date object with the same date component. However without doing a test, I don't know whether timezones might be a complicating factor here.
    Do you have a specific question? Theoretical questions are generally a waste of time both for the questioner and the answerer.

  • New Date().getTime() is returning a negative number

    f I trace new Date().toUTCString() I get something like: Fri Aug 12 07:14:06 2011 UTC. perfect. If I trace new Date().getTime() I get some long negative number which is decreasing as I continue to trace it. This is totally unexpected. Obviously my system clock is OK. What gives?

    hey @kglad, thanks for sticking with this question. At the top of the post I traced: `new Date().toUTCString()` and got: `Fri Aug 12 07:14:06 2011 UTC` My system time is good. Flash is getting the right UTC time. I have restarted since then but have not yet been back in that particular project to see whether the date is tracing something different or still a negative number. I think the next thing to do is to wait until I'm back in there (tongight) and check again.
    I'll update this post!

  • Getting Current time - calendar.getInstance() vs System.getTime...

    Is there a difference between getting a new calendar instance and getting the system time explicitly.
    With regards to getting the current.

    No. Calendar.getInstance() eventually leads to this constructor being called
    (assuming you are not getting the Thai or Japanese Imperial calendar)
        public GregorianCalendar(TimeZone zone, Locale aLocale) {
            super(zone, aLocale);
         gdate = (BaseCalendar.Date) gcal.newCalendarDate(zone);
            setTimeInMillis(System.currentTimeMillis());
        }

Maybe you are looking for