How can I return the current Date in Java?

I am new to Java, and basically I want to know how I can return the current date as a variable, so for example, I have declared the following date variable
private java.util.Date currentDate;How can I return the current date, do I have to write a method? To be more specific, I need to write a setMethod, that simply returns the current Date in Java.
Please point me in the right direction.
Thanks,

If all you want is a date for printing or displaying, the easiest way is to use Date as shown below. If you need something more complex, look at the Calendar API.
import java.util.Date;
class DateEx
     public static void main(String args[])
          Date now = new Date();
          System.out.println(now);          
}

Similar Messages

  • How can I make the current date/time be sent when emailing as XML?

    I'm creating a form for a customer to use for submitting print jobs. This customer will be emailing the XML form data, which will in turn be converted into a production order. I'd like to make the PDF form capture my customer's system time, so that I know when they filled out the form. I COULD just leave that up up the customer and use required current date and time fields, but that provides the ability for the customer to falsify that information.
    Is there any good way to capture the current date/time in the XML data, so that the customer doesn't need to nor has the ability to?
    Any suggestions would be great!

    You can use the following methods getHours(),getMinutes(), and getSeconds() from the date object to obtain the values for hour,minute,and second.
    Click here to see an example:
    http://66.34.186.88/LiveCycleSamples/.3bbc2f4b.pdf

  • How can i get the meta data from database?

    Hi, all java and db experts,
    I need to write a tool to generate java file which will be used to hold the resultset of a stored procedure of Oracle. Is there any API call or tools to connect to db and then get the meta data of the return cursor instead of reading stored procedure definition on my own?
    Please help, thanks a lot.
    Hanna

    if i execute a Oracle stored procedure, the resultset of a cursor is returned. It's easy to know the meta data at the runtime.
    However, could i get the meta data about the resultset of a cursor before runtime? Such as by connecting to the database and ask it about meta data of a specified stored procedure?
    Is it feasible?
    DatabaseMetaData dbmd = conn.getMetaData();
    ResultSet rs = dbmd.getProcedureColumns("", "%", "SP_NAME", "%");
    while (rs.next()) {
    String colName = rs.getString(4);
    int colType = rs.getInt(5);
    int colDataType = rs.getInt(6);
    int colPrecision = rs.getInt(8);
    int colLen = rs.getInt(9);
    int colScale = rs.getInt(10);
    long defaultValue = rs.getLong(11);
    But what i get is a list of stored procedure parameters. In oracle, cursor is IN OUT parameter . How can i get the meta data about the resultset of cursor?

  • I want to update iCloud account with new apple id but don't know password for old apple id.  Plus can no longer receive email at old apple id.  How can I delete the current iCloud account on my iPhone if the previously stated conditions exist?

    I want to update iCloud account with new apple id but don't know password for old apple id.  Plus can no longer receive email at old apple id.  How can I delete the current iCloud account on my iPhone if the previously stated conditions exist?

    If the old ID is yours, and if it is an earlier version of your current ID, go to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Click edit next to the primary email account, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iDevice, even though it prompts you for the password for your old account ID. Then save any photo stream photos that you wish to keep to your camera roll.  When finished go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https://appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • Please help.........how can i get the last date of the month?????

    Hello....
    I want to get the last date of the month.
    For example, the last date of Jan is 31.
    How can I get the last date of the particular month and year ????
    Thanks for help.
    Gloria

    Hi Gloria
    1. How can I compare the date???date1.compareTo(date2)
    where date1 and date2 is a java.util.Date Object
    will return 0 if it is the same date
    or
    date1.after(date2)
    where date1 and date2 is a java.util.Date Object
    will return true if date1 is after date2
    (the same for date1.before)
    2. How can I change the date format into yyyymmdd format???? I just want the year, month and date.try the java.text.SimpleDateFormat Object
    new SimpleDateFormat("yyyymmdd").format(yourdate)
    Hope this help.
    Please also have a look at a calendar I wrote, (maybe it help)
    demo & source :
    http://www.geocities.com/globe_software/java/components/
    globe_sa

  • HOW CAN I EXTRACT THE SYSTEM DATE?

    HOW CAN I EXTRACT THE SYSTEM DATE?

    import java.util.*;
    import java.text.SimpleDateFormat;
    public class date2{
        public static void main(String[] args){
            Date today = new Date();
            SimpleDateFormat output = new SimpleDateFormat();
            String answer = output.format(today);
            System.out.println(answer);
    }If you want to make it prettier, you can look at using a locale, or a pattern string in the SimpleDateFormat constructor. Read the Documentation.
    Note that new Date(), constructs a Date with the current Time,
    you could also use: new Date(System.currentTimeMillis());
    Hope this helps
    -Philip.

  • HELP! Last second extra credit (before midnight), how can i return the node

    While traversing a tree... How can i return the node I am currently at?

    Or perhapspublic Node getCurrentNode() {
      return currentNode;
    }Your question has a large number of possible interpretations.

  • How can I restore the game data from an old ipod touch to a new one?

    How can I restore the game data from an old ipod touch to a new one?

    Restore it from the backup of the old ipod.

  • I have made a burn folder with photos exported from I-photo.  It now shows in information, that the date is created and modified is different from the original digitized date.  How can I get the original date to show in the info from Finder?

    I have made a burn folder with photos exported from I-photo.  It now shows in information, that the date  created and modified is different from the original digitized date.  How can I get the original date to show in the info from Finder?

    The Finder reports File information. The date and time of the photo are in the Photo's Exif metadata. The Finder has no awareness of this. All photos apps on any system do.
    Regards
    TD

  • HT204150 i have deleted all contacts in icloud but still have them on my iphone (which is backed up as well to iTunes) how can i restore the iphone data to the iCloud so it will resend it to my mac book and iPad?

    i have deleted all contacts in icloud but still have them on my iphone (which is backed up as well to iTunes) how can i restore the iphone data to the iCloud so it will resend it to my mac book and iPad? I have switched my iphone to airplane mode so it is not connected to the internet and so icloud can not wipe it at the moment.
    thanks roy

    There's a menu choice (I think under "Files") that lets you sync purchased items on a device back to itunes.  Look for that.
    iCloud does not store music.  If you want to do that you'd have to subscribe to itunes Match, but to get music to the match servers, you need the music in the itunes library on your computer.

  • How can I set the insert date to auto update in Pages 5.2.2

    how can I set the insert date to auto update in Pages 5.2.2
    I am attempting to have the date in header auto update in a Pages file.
    I can insert it, but where is the AUTO UPDATE selection
    OS10.9.4
    thank you

    Apple never included the auto-update feature for dates in Pages v5.2.2. You would have to single-click the date, and deliberately update it.
    If you have Pages ’09 v4.3 in /Applications/iWork '09, then it will allow you to configure auto-update of the date field. Right-click on the date, set the format, and click the selection for automatically update on open.

  • How can I check the expiration date of a Certificate Keychain from terminal?

    Hello, I am writing a bash script to alert me when my corporate certificates are about to expire. How can I check the expiration date of a certificate in keychain? I'm running Mac OS 10.6.8 on a newer MacBook pro with full admin rights.
    Specifically I will be checking three certs: a Root Authority, Issuing Authority, and a user cert (Identity).
    I was exploring the Security and Openssl command line tools. But I can't seem to get the info I need.
    Any recommendations would be appreciated.
    Thank you!

    Anyone?

  • How can I get the system date in mm/dd/yyyy,

    how can I get the system date in mm/dd/yyyy, i need to compare system date with some other date,continuosly using threads,can U plz help me.
    With Some code
    Thanks In advnace
    Mahiiii

    Hi,
    You can use SimpleDateFormat class under java.text package.
    SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy h:mm a z", new Locale());
    //formatter.setTimeZone(timezone);
    String dateTime = formatter.format(new Date());

  • TS1702 How can I return the app that I bought for my iPhone4S almost three months ago.

    How can I return the app I bought almost 3 months ago? Is this to late to return??

    Apps are not returnable. They're also very difficult to wrap.

  • How can I get the current user an  resource context  in a portal JSPDynPag

    How can I get the current user (com.sapportals.portal.security.usermanagement.IUser?)an the resource context  in a portal component (JSPDynPage)?
    Thanks.

    Hi Jon,
    Here is the code to get the current user and resource context in your JSPDynPage:
    IPortalComponentRequest  currentRequest  = (IPortalComponentRequest)pageContext.getAttribute(javax.servlet.jsp.PageContext.REQUEST);
    com.sapportals.portal.security.usermanagement.IUser contextUser = (com.sapportals.portal.security.usermanagement.IUser) currentRequest.getUser().getUser();
    ResourceContext resourceContext = new ResourceContext(contextUser);
    Greetings,
    Praveen Gudapati
    p.s. points are always welcome for helpful answers

Maybe you are looking for