How to get server date and time using java code

Hi,
I'm new to java. I have one doubt about getting date and time of the server. can anyone give some sample code to get that.
thanks in regards
Gopi.

you need 2 things
1. something on the application server which exposes the servers time/date
2. something on the client which makes use of your time service
for instance, you could write a ServerTimeServlet that clients can call to get the time according to the server. or, if you've got a database in the server, often database software will provide a Time procedure or similar that does this, so you can use a simple SQL query to get the latest time

Similar Messages

  • How to get system date and time?

    Can someone show me a code on how to get system date and time.
    Thanks!

    there is one really easy way to get system time, the api gives a great example of code on this. use gregorian calendar, which you'll find in the api under GregorianCalendar. You only need to create one instance of GC, ie Calendar time = new GregorianCalendar();
    you save seconds, minute and hours into int values, so you don't have to access the system time every second, you can create a thread which adds one to the int second value, if oyu see what i mean, for example, i have saved the hours, minutes and seconds as int values;
    int hour, minute, second;
    i can then create a thread (Thread thread = new Thread(this) and run it like:
    Calendar time;
    int hour, minute, second;
    Thread thread = null;
    public MyTime() {
    hour= time.get(Calendar.HOUR_OF_DAY);
    minute = time.get(Calendar.MINUTE);
    second = time.get(Calendar.SECOND);
    if(thread == null) {
    thread = new Thread(this);
    thread.start();
    public void run() {
    Thread t = Thread.currentThread();
    while(thread == t) {
    thread.sleep(1000);
    second++;
    if(second > 59)
    minute++;
    if(minute>59)
    hour++;
    formatTime();
    public void formatTime() {
    second = (second > 59? 0 : second);
    minute = (minute > 59? 0 : minute);
    hour = (hour > 23? 0 : hour);
    System.out.println(hour+":"+minute+":"+second);
    public static void main(String[] args) {
    new MyTime();
    I know this looks like gibberish but it should work. If not, try to fix the problem, i have written from memory really but i guarantee you, this gets the time then every second, simply adds one to the second and then formats time. You can also access the day, month and year then format them using the above code. I don't like giving code since you should really do these things yourself but it is 2:04am, i have nothing better to do and i am not tired so i did you a favour - i have become what i always did not want to, someone ho stays upall night writing code.

  • Problem with getting current date and time using oracle.jbo.domain.Date

    I`d like to get current date and time using oracle.jbo.domain.Date method getCurrentDate(), but it always return current date and 12:00:00. I also need to get the current time.

    I think you should use java.sql.Timestamp domain.
    (And set database type to TIME or DATETIME.)
    Jan

  • How to get the date and Time?

    Hi,
    I am using Jdev 11.1.2.0.
    I had one database table. In that table one variable as bgnDtm and the datatype as oracle.jbo.domain.Timestamp. In my Impl class I declare one variable as beginDate(DateType as oracle.jbo.domain.Date).
    Now I am using the conversion as beginDate=(Date) SampleVO.getAttribute("bgnDtm ");.If I using this scenario I got the Type cast error. so how can I separate Date and Time value.
    So how to do. Please provide some suggestions.
    Regards,
    Ragu.

    you can get the time value either from oracle.jbo.domain.Timestamp or from oracle.jbo.domain.Date
    oracle.jbo.domain.Timestamp timeStampDate = (oracle.jbo.domain.Timestamp) SampleVO.getAttribute("bgnDtm");
    Time time;
            try {
                time = timeStampDate.timeValue();
                System.out.println(time);
            } catch (SQLException e) {
                e.printStackTrace();
            java.sql.Date sqlDate=timeStampDate.dateValue();
                oracle.jbo.domain.Date jboDate=new oracle.jbo.domain.Date(sqlDate);
            Time timeValue = jboDate.timeValue();
            System.out.println(timeValue);Edited by: M.Jabr on Dec 23, 2011 1:55 PM

  • How to get the system date and time using java

    hi,
    I want system date in my out put. how to access system date. can v use utill packaegs (or) sql. which one is the best to get.
    Thanks & Regards,
    Kenny.

    import java.util.Date;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    public class MyClass {
    public void setTimeStamp() {
    int hour, minute, second, time = 0;
    Date dt=new Date();
    System.out.println(dt.getDate());
    System.out.println(dt.getMonth());
    System.out.println(dt.getYear());
    Calendar cal = new GregorianCalendar();
    hour = cal.get(Calendar.HOUR_OF_DAY);
    minute = cal.get(Calendar.MINUTE);
    second = + cal.get(Calendar.SECOND);
    System.out.println (hour + ":" + minute + ":" + second);
    public static void main (String args[]){
    MyClass app = new MyClass();
    app.setTimeStamp();
    }

  • How to get exact date and time difference?

    Hi,
    When i am using the below sql statement:
    SELECT (TO_DATE('7/27/2006 05:00:15 PM','MM/DD/YYYY HH:MI:SS PM') - to_Date('7/27/2006 8:30:13 AM','MM/DD/YYYY HH:MI:SS AM')) * 24 hours FROM DUAL;
    the output is:
    Hours
    8.50055555555556
    But Actually it is 8.30
    So how can i get exact days and time difference between two dates in Oracle?
    Thanks....
    Regards,
    Suman Sakinala
    Edited by: SSN on Sep 19, 2008 1:27 AM

    Or more clearly (this time I have my date_from and date_to the right way around hehe!)
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as (select TO_DATE('7/27/2006 05:00:15 PM','MM/DD/YYYY HH:MI:SS PM') as dt_to,
      2                    TO_DATE('7/27/2006 08:30:13 AM','MM/DD/YYYY HH:MI:SS AM') as dt_from FROM DUAL)
      3      ,d as (select (dt_to-dt_from)*24 as diff_hrs from t)
      4  -- end of dates
      5  SELECT TRUNC(diff_hrs) as hours
      6        ,TRUNC(((diff_hrs) - TRUNC(diff_hrs))*60) as mins
      7        ,TRUNC(((((diff_hrs) - TRUNC(diff_hrs))*60) - TRUNC(((diff_hrs) - TRUNC(diff_hrs))*60))*60) as secs
      8* FROM d
    SQL> /
         HOURS       MINS       SECS
             8         30          2
    SQL>

  • How to get the date and time of the last KM scheduled run

    Hi Experts,
    I had a scenario where i need to send the last date and last time when the KM schduler runned.?
    Issue:
    I have created a Km sheduler, in that i have written the jave code to retrieve the details from a function module and getting the output from Func module and sending an email  to one administrator.It worked fine for me.this scheduler will run for every 20 mins.
    But now Abapers have included two import parameters in their Function module " Last date and last run".So i need to populate this iimport parameters dynamically.
    How can i acheive this?
    Please assist.Thanks in Advance.
    Thanks
    Sony.

    java.util.Date date = java.util.Calendar.getInstance().getTime(); //retrieve a date object
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(dd-MMM-yyyy);
    String s = df.format(date); //10-Aug-2001
    String t = "15042001";
    df.applyPattern("ddMMyyyy");
    d = df.parse(t);
    df.applyPattern("dd-MMM-yyyy");
    t = df.format(d); //15-Apr-2001Hey it's Friday, I'm bored

  • Does anyone know how to get specific date and time on an itouch

    I need secific times on  safari searches in my history, there is a legal implication and I need to know if its possible to get the info, or can an apple store get anything. the history is in there but it just gives the date not time.
    Thanks in advance

    a) Open the document with it's password.
    b) Pick "Duplicate" from the File Menu
    c) Pick "Save As..." from the File Menu.

  • Get  current date and time

    hello.
    How can I get current date and time in JAVA?
    Thanks.

    Sorry, I mean:
    how can I get the value of DATE, MONTH, and YEAR of the
    current date?
         Date date = new Date();
         System.out.println(date);

  • Camileo S20 - How to display the date and time

    Hi, to all. I have got as Christmas present the Camileo S20 and I am not able to display the date and time at video. In manual is no mention about this, just how to set the correct date and time. But what is intention of setting the date and time into camera, if it is not possible to display them on video ?

    Hi,
    of course, I did it repeatly, it is written in my question above. I am not stupid.
    This question is aimed to owners of camera Camileo S20 and also Camileo S10 - Camileo S20 is derived of Camileo S10, may be any of them discovered the way how to get the date and time into video.

  • Getting the date and time from NIST server

    I need to be able to get the date and time in an app and cannot trust the device's clock since the user could change it. Has anyone got an example of how to access an Internet time server such as the NIST servers from AIR for iOS?

    What is the best way to get the date and time?
    ThanksI am not sure that this is the best way. But one of the ways.
    <code>
    java.util.Date d = new java.util.Date();
    System.out.println("date is "+d.toString());
    </code>

  • How can I get the date and time and display it on the report main page?

    Gurus,
    How can I get the date and time and display it on the report main page?
    Thanks!

    Hello,
    You can create a Formula Colum returning a date :
    function CF_1Formula return Date is
    begin
    RETURN(SYSDATE);
    end;
    Put a Field in the Layout having this formula column as source .
    Regards

  • How to find the Date and Time of Modification of Column in aTable?

    Hi all,
    Do  you know how to find the Date and Time of Addition of Column to a Particular Table?.
    I know however, How to find the modification time of the Table. Using the below Query :
    Select Object_Name, to_Char(Last_DDL_TIME, 'DD-Mon-YYYY HH24:MI:SS') Last_DDL from User_Objects where Object_Type = 'TABLE';
    Object_Name
    Last_DDL
    Employee
    20-Aug-2013 09:23:03
    I wanted to know the Creation or Modification Date and Timestamp of all columns of Employee Table?. Is it possible at all. If possible, How to get it?.
    Regards,
    Bhaskar M

    I agree with you on that. Since its a development enviornment I can remove the column but that not my point here.
    My whole purpose it to know whether we get the Column's Creation or Modification DateTime.

  • Get the date and time from iframe.

    Hi,
    Am using jdeveloper 11.1.1.6.0., I have used the following iframe source which gets the date and time.
    <af:form>
    <iframe src="http://free.timeanddate.com/clock/i3xb4nm0/n1722/tt0/tw0/ts1" frameborder="0" width="244" height="19">
          </iframe>
    </af:form>
    I need to get the date and time separately to perform some validation. How can i  get it.
    regards,
    Prasad K T,
    9840021070

    Prasad,
    I don't understand your use case. The url you use is a json web service which returns it's result as either xml or json payload. Why do you pretty print this as a web page and try to get to the result this way?
    Why don't you get the result directly using the json result or (AFAIK) the java script api which the service also provides.  Check the documentation of the service.
    From your description I understand that the user enters a time. You need to know if the time is before or after 2:30pm and have to set a 'shift' to A or B.
    Where do I need a timeservice in this validation?
    From what I see your approach won't work. As I still don't understand the use case I don't know how to help.
    Timo

  • Gettig server date and time

    how can i get the server date and time and to storage it in a time and date variable?
    please send me full code, i�m new programing in java.
    thank you very much,
    luis torres.

    here is the point.
    I WANT TO CHANGE THE FOLLOWIING LINES TO DO NOT TO CAPTURE THE TIME ( "HORA" IN SPANISH), I WANT TO GET THE SERVER TIME AND PUT IT DIRECTLY INTO THE : pc_Checadadiariaaddtest.altachecadadiaria.HORA FIELD.
    THIS IS THE CODE I WANT TO CHANGE, PLEASE HELP ME:
    /tr><tr>
         <td align="left">Hora: /td>
         <td style="width:5px"> </td>
         <td><h:inputText id="text1" value="#{pc_Checadadiariaaddtest.altachecadadiaria.HORA}" styleClass="inputText" >
    <f:convertDateTime/>
    </h:inputText>
    </td>
    </tr>
    GIVE TO ME THE EXACT CODE I NEED TO WRITE. PLEASE.
    THANK YOU VERY MUCH FOR YOUR HELP.
    LUIS TORRES
    MEXICO.

Maybe you are looking for

  • Suppress cloumn in ALV

    How to suppress column in ALV?

  • EAR Deployment Problem with weblogic 10.2. Need help.

    Hi, I have a EAR file exported from MyEclipse IDE. When i am deploying the EAR file in weblogic 10.2, i am not seeing classess and properties were not exploded under WEB-INF/classes in the web project. I can see the classes folder but it's empty. Whe

  • Editing for multiple output formats

    Sorry if this is a stupid question...I'm just getting started with FCE. I'm working on a movie that I want to use in multiple places: - HD version to play directly from computer onto HD display - regular definition DVD - web sized video My source mat

  • Stop session in ODI procedure

    Hi, I have 3 scenarios in 1 package. In my first scenario i have a condition in procedure and when my condition is false i would like to stop de session for the first scenario not for the package. I try to create a object (currentsession) in jython.

  • Won't print, no printer settings box, just a ding on ctrl-p

    Whenever I try to print a web page using either ctrl-p or File Print, all I get is a ding. No printer setup box or anything.