Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Java: how to get the date/time

Posted on 2014-02-04
2
317 Views
Last Modified: 2014-02-10
Hello,
  I have to run a dynamic query to get data from 12:00AM of the current day to the current date/time.

I know how to current date/time . How do I get the start of the day . The format should be
'YYYY -MM-DDThh:mm:ss.nnnZ' e.g 2014-02-04T00:00:00.000Z

Thanks for your help
0
Comment
Question by:SiemensSEN
2 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 200 total points
ID: 39834200
Depending on exactly what you will do with it, something like the following should work...
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date startOfDay = cal.getTime();

Open in new window

The format should be ...
The format is only specified when you convert the Date value to a String value. If you are using anything like JDBC (or a higher level abstraction) you should be passing your Date values (or a similar type) directly to the API for running your query. You shouldn't need to be converting it to a String. If this isn't clear, can you post the code of how you are running your query and I can be more specific.
0
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39834897
In short you want a data for current date.  Any reason for time format?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question