Solved

Java: how to get the date/time

Posted on 2014-02-04
2
303 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
Comment Utility
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
Comment Utility
In short you want a data for current date.  Any reason for time format?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now