?
Solved

Java: how to get the date/time

Posted on 2014-02-04
2
Medium Priority
?
329 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
[X]
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
2 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 800 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

777 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