Date/Time Question - Milliseconds
How can I get the number of milliseconds after the 1970... from a date?
Is there such a method in the API? I looked at the DateFormat and NumberFormat classes but I didn't find it... Is there a way a to do this?
I want to be able to give a date and get back the number of milliseconds past the 1970 thing...
Thanx
DrClap has a good solution. Here is another twist:
// Do this
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Date start = formatter.parse("01/01/1970");
// Or do this
Calendar calendar = Calendar.getInstance();
Calendar.set(1970, Calendar.JANUARY, 1);
Date start = calendar.getTime();
return (new Date().getTime() - start.getTime());- Saish
Similar Messages
-
Is the date/time in Milliseconds dependent on the underlying timezone
Hi,
A Timestamp is received as an argument to a method. It is meant to be for the Time Zone "America/Los_Angeles".
The value of the Timestamp is "2001-06-06 10:10:10.1".
The JVM Time Zone is "America/New_York".
The output of <Timestamp>.getTime() is
991836610000
Then I change the default Time Zone to "America/Los_Angeles" and create a new Timestamp with a value of
"2001-06-06 10:10:10.1". The same as the above Timestamp.
The output of <Timestamp>.getTime() is
991847410000
If I create a new Timestamp object using the value of 991836610000 milliseconds when the default Time Zone is "America/Los_Angeles", the date/time that is given is
"2001-06-06 07:10:10.1
The API for <Date>.getTime() states that "Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.". It doesn't mention that it is dependent on the Time Zone in which the Date object was created. Hence I was assuming that the same value will be returned irrespective of the Time Zone the Date object was created in. However it appears not to be so.
Is there a way to work with date/time objects without been influenced by the underlying default Time Zone? i.e without having to change the underlying Time Zone when working with objects created in one Time Zone and with a need to be applied to a different Time Zone?
Thanks
HarshaAs malcolm pointed out, the problem is that when you parse the date, a reference timezone must be used. If you don't explicitly specify a reference timezone, the default timezone will be used.
Is there a way to work with date/time objects without
been influenced by the underlying default Time Zone?
i.e without having to change the underlying Time Zone
when working with objects created in one Time Zone and
with a need to be applied to a different Time Zone?Make sure you specify which timezone the parsed time is in:
String localTime = ...;
TimeZone localTimeZone = ...; // you presumably know this
DateFormat df = ...; // get a formatter for parsing your date
df.setTimeZone(localTimeZone);
Date date = df.parse(localTime); -
Does anyone know if there is a way to DESELECT the "Automatically update the date and time when the document is opened" dialog?
Thanks.
PaulThe only way I can see is to create your own template with this unchecked. Then, when you open this template, auto date & time should be unchecked.
It would be nice if this were a global preference. I suggest you leave feedback for the Pages team. -
Hi, I'm a new Java programmer.
I need to format a date/time variable from sql server into two string objects. One string object storing the date and the other storing the time.
I've tried using the Date class and DateFormat class, but I haven't found a way yet.
Can anyone help me?
Thanks a lot,
louisYou could try something like this:
Date dateAndTime = /* read date from sql server */;
DateFormat dateOnly = new SimpleDateFormat("yyyy-MM-dd");
DateFormat timeOnly = new SimpleDateFormat("HH:mm:ss");
String dateString = dateOnly.format(dateAndTime);
String timeString = timeOnly.format(dateAndTime); -
Date + Time question updating to a DATE field..
Hi,
I'm going crazy...
MEETING_DATE is a DATE column in the DB
:P40_MEETING_DATE is a TEXT FIELD with source MEETING_DATE
:P40_MEETING_DATE:=to_char(to_date('02-OCT-2006 09:14:45 PM','DD-MON-YYYY HH:MI:SS PM'),'DD-MON-YYYY HH24:MI:SS');
Ultimately I need to have :P40_MEETING_DATE a date picker and then
add a character string of a time to it.
:P40_MEETING_DATE:=to_date(to_char(:P40_MEETING_DATE,'date picker format?')||' '||:P40_START_TIME,'date picker format?');
I get all kinds of errors ORA-01858 errors.. non- numeric errors.. invalid month errors..
BillYou are right, sorry about that.
I thought about sneaking a On Submit - After Computations and Validations process in there before the Process Row process like this:
:P216_X := TO_DATE( TRUNC( TO_DATE( :P216_X, 'DD-MON-YY HH24:MI' ) ) || ' ' || :P216_TIME, 'DD-MON-YY HH24:MI' );but that's probably the same thing you tried before.
I would just turn it into a procedure and pass the parameters...;)
I hope someone can get your going in the right direction.
chet -
ok so I can print out the date and time when i run the program.
How would I write a method that updated the clock every second, kinda like a digital watch. would I just use a while loop? or does java have an actual running clock?
Here is the code I have so far:
import java.util.Date;
public class DateTime
Date now = new Date();
public DateTime()
System.out.println(now);
public static void main(String[] args)
DateTime run = new DateTime();
}import java.util.Date;
public class DateTime
Date now = new Date();
public DateTime()
{while(true){
System.out.println(now);now = new Date();
Thread.sleep(1000);
public static void main(String[] args)
DateTime run = new DateTime();
I modified your code a bit better do this in a different thread though if you plan to use a GUI -
Another DATE/TIME question
HI all
I am trying to INSERT INTO TABLE a date and time into one line..
excerpt looks like
CREATE TABLE Test
(Submit DATE );
INSERT INTO Test
VALUES(to_date('2001-01-02 22:23:00','yyyy-mm-ss hh24:mi:ss'));
I get an error message that says it's missing a comma (and I can't figure out WHERE). I have tried quotes in different places etc...Is it not possible to put a date and a time in the same slot?
Thanks in advanceTry this...
SQL> create table mytest (submitted date);
Table created.
SQL> desc mytest
Name Null? Type
SUBMITTED DATE
SQL> insert into mytest
2 (SUBMITTED)
3 values
4 (to_date('2001-01-02 22:23:00','yyyy-mm-dd hh24:mi:ss'));
1 row created.
SQL> select * from mytest;
SUBMITTED
02-JAN-01
HI all
I am trying to INSERT INTO TABLE a date and time into one line..
excerpt looks like
CREATE TABLE Test
(Submit DATE );
INSERT INTO Test
VALUES(to_date('2001-01-02 22:23:00','yyyy-mm-ss hh24:mi:ss'));
I get an error message that says it's missing a comma (and I can't figure out WHERE). I have tried quotes in different places etc...Is it not possible to put a date and a time in the same slot?
Thanks in advance -
Newbie: Date time question
I want to store a date and time into the same column. But I do not know the syntax to do it and to select it.
Can anyone help me?Oracle should store this anyway - all you need to do to see this is to set the nls_date_format for the session you are using to 'DD-MON-YYYY HH24:MI:SS'
GR -
Problem 1:
i'm using date in midlet, but it does not give me the correct System time.
Problem 2:
the date field returns the date & time in milliseconds. how can i get the date in format 06 sep 2002.Hi,
You can use the method System.currentTimeMillis(), that returns a long value that is your system's current time.
DateField dateField = new DateField("Date", DateField.DATE_TIME);
dateField.setDate(new Date(System.currentTimeMillis()));
To get the day, month and year you can use the Calendar class.
Calendar calend = Calendar.getInstance();
calend.setTime(new Date(long yourdatemillis));
So you can get the correct parameters by calling
calend.DAY_OF_MONTH, calend.MONTH and calend.YEAR and appending it to a String and displaying it. But the day of month and month, i think, returns the correct value decreased of 1.
Ricardo -
Q: How to get local time in milliseconds?
Hi,
As we know, Labview a G function which can get local date/time in
seconds. Is there any way to get local date/time in milliseconds? Or it
also helps if you know there is any similiar function in C/C++.
Thanks!
G. Chen
Ph.D. Candidate
Ohio Univeristy, Athens, OH
Nothing can dim the light which shines from within.
Sent via Deja.com http://www.deja.com/
Before you buy.> As we know, Labview a G function which can get local date/time in
> seconds. Is there any way to get local date/time in milliseconds? Or it
> also helps if you know there is any similiar function in C/C++.
>
The local time function returns a double precision number.
Depending on the platform you are using, the number returned
may have a subsecond amount. This means that you subtract
and multiply by 1000 to get ms. The platform that returns
this is Win32, and its resolution is 55ms. Other platforms
will always return 0.
It is also sort of possible to synch the ms function with
the local time function, but this is not very accurate.
It involves watching the local time function in a loop
until it changes, and also sample the ms clock to synchronize
the two clocks.
From that point on, you can use the ms
function exclusively, and do the math to get back to local
time. The problem with this is that the fast clock rolls over
about every 40 days, the clock may have some drift with the
local clock, and then there is daylight saving time and time
zone math, which is always surprisingly complex.
Greg McKaskle -
Time Zone Offset - Date Format question
I'm wondering if any one knows how to display the time zone offset of a date in the following format "[+-]HH:mm." More so... I need the date/time in the ISO 8601 format "yyyy-MM-dd'T'HH:mm:ss[+-]HH:mm", where the last [+-]HH:mm is the hour representation of the offset. Here's some sample code...
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Calendar rightnow= Calendar.getInstance();
// So if system date/time is February 14, 2002 at 1:15:00 PM EST, this would produce "2002-02-14T13:15:00"
System.out.println("Current Datetime" + sdf1.format rightnow.getTime());
How can I get the timezone offset appended to my output in a [+-]HH:mm format. So, the above date needs to look like "2002-02-14T13:15:00-05:00". I can get the offset in milliseconds by doing the following:
int offset1 = rightnow.get(rightnow.ZONE_OFFSET) + rightnow.get(rightnow.DST_OFFSET);
But how can you get this representation into the [+-]HH:mm format?
thanks in advance,
stophmanTry something like this:import java.text.* ;
import java.util.* ;
static public String formatISO8601(Calendar cal) {
* create ISO 8601 formatter for Calendar objects
MessageFormat iso8601 = new MessageFormat("{0,time}{1,number,+00;-00}:{2,number,00}") ;
// need to shove a date formatter that is cognizant of the
// calendar's time zone into the message formatter
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") ;
df.setTimeZone(cal.getTimeZone()) ;
iso8601.setFormat(0, df) ;
* calculate the time zone offset from UTC in hours and minutes at the current time
long zoneOff = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET) ;
zoneOff /= 60000L ; // in minutes
int zoneHrs = (int) (zoneOff / 60L) ;
int zoneMins = (int) (zoneOff % 60L) ;
if (zoneMins < 0) zoneMins = -zoneMins ;
return (iso8601.format(new Object[] {
cal.getTime(),
new Integer(zoneHrs),
new Integer(zoneMins)
} -
Java Time Counter / Date Class Question
I am trying to make a program that if a input is recieved it will record the time and when another input is recieved it will record the time as well.
I am sorry of stupid question:
1. how do i minus both "timing"? i try to directly minus it, but doesn't seem to work .
2. in the java Doc it say it can only take up to milli seconds. Is this the smallest time unit i could mesaure?I am trying to make a program that if a input is
recieved it will record the time and when another
input is recieved it will record the time as well.
I am sorry of stupid question:
1. how do i minus both "timing"? i try to directly
minus it, but doesn't seem to work .
2. in the java Doc it say it can only take up to milli
seconds. Is this the smallest time unit i could
mesaure?1.
long start = System.currentTimeMillis();
// do something
long end = System.currentTimeMillis();
long elapsed = end - start; //ms
2.
No there are smaller.
Java Tiger (1.5) offers a nano unit for measuring issues.
currentTimeMillis()
Returns the current time in milliseconds.
nanoTime()
Returns the current value of the most precise available system timer, in nanoseconds.
good luck! -
Adding Date/Time Field + X Number of Days - Basic Calculation Question
I am assuming this is a basic calculation question. New to Adobe LiveCycle Forms.
I have a simple form containing a table. The table appears as such:
Text
Formatted as Date/Time Fields
Header 3
Monday
user wil choose the beginning date (Date/Time) this is DateTimeField1
Tuesday
this should calculate DateTimeField1 + 1
Wednesday
this should calculate DateTimeField1 + 2
Thursday
this should calculate DateTimeField1 + 3
Friday
this should calculate DateTimeField1 + 4
Saturday
this should calculate DateTimeField1 + 5
Sunday
this should calculate DateTimeField1 + 6
Calculations are performed after the date is chosen for Monday. My mind tells me the simple calculation of DateTimeField1 + 1 is not going to work (and in fact doesn't!) as it needs to change Monday to a number first. I saw on another thread the following:
Num2Date(Date2Num(Date(DateTimeField1), "DD.MM.YYYY")+7, "DD.MM.YYYY")
Thought this was going to get me close. No cigars though!
Any quick help is greatly appreciated. And since I am new to this, details about what needs to be changed would be great too!
ThanksHere an addition for you date field.
This FormCalc script in the exit:Event will check it the selected date is on a monday.
If not it will go the days back until the last monday.
var Selection = Date2Num($.formattedValue, DateFmt(2))
var WeekDay = Num2Date(Selection, "E")
var NewDate
if (WeekDay eq 1) then
NewDate = Selection - 6
elseif (WeekDay eq 3) then
NewDate = Selection - 1
elseif (WeekDay eq 4) then
NewDate = Selection - 2
elseif (WeekDay eq 5) then
NewDate = Selection - 3
elseif (WeekDay eq 6) then
NewDate = Selection - 4
elseif (WeekDay eq 7) then
NewDate = Selection - 5
else
NewDate = Selection
endif
$ = Num2Date(NewDate, "EEE DD.MM.YYYY")
Hope this helps, too. -
Question on date, time and time stamp related - high priority
Hi friends,
My requirement is to find the processing time (time taken) of a task done by an agent in wf. For that I use Start Date, Start Time, End Date and End Time ( from struc SWP_LOGTAB ). I have to display the time taken by an agent in the form WWd XXh YYm (or WWd XXh YYm ZZs) ex: 2d 10h 40m 20s.
Can any one suggest me the right FMs which take start and end date/time and give me the above format result?
This can be achieved manually with unnecessary Ifs and CASEs but its gonna be a performance issue. Please suggest me something SAP standard.
Thanks in advace for your help
ReddyHi,
I don't find any function module, but it does'nt really hard to code this using DIV and MOD instructions :
If you've got your time in seconds :
w_day = w_time DIV 86400.
w_mod = w_time MOD 86400.
w_hour = w_mod DIV 3600.
w_mod = w_mod MOD 3600.
It doesn't seem too bad in term of performance....
Mathieu -
Adobe LiveCycle Date/Time Field Scripting Question
I have a date/time field in Livecycle which the end user chooses a random date from. I need to populate a date 180 days from this date for an eligible to date/time field. I have tried various javascript and formcalc options with no success.
Try this site here for a reference: http://eslifeline.wordpress.com/2008/09/26/date-manipulation/
The following was the use case. A form has 2 TextFields Start_Date and End_date
User enters a certain date in the Start_Date text field for example 09/24/08 (MM/DD/YY)
The End_Date should add 90 days to the Start_date and populate the End_Date
The following script would do that
var current = Date2Num(Start_Date.rawValue, “MM/DD/YY”)
var future = current+90
var newDate = Num2Date(future,”MM/DD/YY”)
form1.#subform[0].End_Date.rawValue = newDate
Validating End Date is later than Start Date
var diff = Date2Num(EndingDate.rawValue, “YYYY-MM-DD”) – Date2Num(StartingDate.rawValue, “YYYY-MM-DD”)
if (diff > 0) then
xfa.host.messageBox(“The End date is later than start date”)
else
xfa.host.messageBox(“PLEASE CHECK….The End date is before the start date”)
endif
Maybe you are looking for
-
Non invoice related deductions through EDI
I am trying to automate the cash application process via the receipt of the customer inbound 820 (using message type REMADV, type PEXR2002). I can successfully post payment, clear open items, and set up deductions relating to a specific invoice, but
-
HI, 1. I downloaded one smartform. If in that text in the text element is written ater some spaces. IF i upload the same form ,will the layout come same, or text in the textelements is moved left? 2. How can i see history of changes done to
-
Dom parsing -- ruturning null?
when trying to parse an xml file using DocumentBuilder.parse, i dont get any exceptions, it just returns null. I wrote a succinct Test class to debug and still cannot find the problem. below is the output, and the method i wrote. thanx for your help:
-
Lost installation disk, photoshop elements 7
Hi, I cannot locate my installation disk for photoshop elements 7, and I'd like to install it on my new laptop. i did register the program on adobe.com way back when I got the disk, but given that it was a physical installation disk (vs. a download
-
New iPod Classic needs Vista, I have got Windows 2000. Any way round this?
I have just run over my iPod photo 60 GB with the lawn tractor and reduced it to tiny fragments! Having purchased a replacement, in the form of a Classic 120 GB, I now find that it requires a later version of iTunes - which also requires a later vers