[java] getTimeInMillis

Started by
1 comment, last by nerak 20 years, 9 months ago
Has anybody implemented de function getTimeInMillis? I have de standar 1.3.1 JDK, working with OC4J. The message I get is the following: No method matching getTimeInMillis() found in class java.util.Calendar. diffMillis = fecha2.getTimeInMillis(); My code is: <%@ page import="java.io.*" %> <%@ page import="java.net.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.util.*"%> <%@ page import="java.text.*" %> <%@ page import="java.lang.*" %> <%@ page import="java.text.DateFormat" %> <% Calendar fecha2 = Calendar.getInstance(); fecha2.set(Calendar.DAY_OF_MONTH, 12); fecha2.set(Calendar.MONTH, 10); fecha2.set(Calendar.YEAR, 2000); long diffMillis=0; diffMillis = fecha2.getTimeInMillis(); %>
Advertisement
try System.currentTimeMillis()
Since calendar.getTimeInMillis() is protected you can''t call it from outside the object or one of its subclasses.

I think you could call fecha2.getTime().getTime()

The first getTime() returns a java.util.Date from the Calendar object, and the second getTime() returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object. This is all if you''re trying to get the milliseconds for some arbitrary calendar date. If you just want the current system time then listen to tortoise.

This topic is closed to new replies.

Advertisement