Solved

Java: how to get the date/time

Posted on 2014-02-04
2
318 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

749 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