Add Hours To Date In Java
I’ll come out clean on this. Lately I’ve been doing some Java and I have to say that the other side is not all that bad as it’s projected to be. Most of my Java work is around integration with .NET and I’m lovin it.
My forays into Java and other non-Microsoft technologies is a post for another day. Today I just want to share some simple code which I wrote while I was struggling with a simple requirement. The requirement is to add x number of hours to current Date-Time.
I found that the best way to do this is by using Calendar class from java.utils package. Here is the code I wrote.
public static void main(String[] args) {
// Create a new calendar object
Calendar calendar = Calendar.getInstance();
System.out.println(calendar);
// Add 5 hours to current time
calendar.add(Calendar.HOUR, 5);
System.out.println(calendar);
}
Each day as I work with Java I find things that seem interesting especially for a .NET guy. I’ll keep posting them.
Tagged with: Java
Top Posts
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Windows 7 Control Panel In Classic Mode
- More Details Emerge On Microsoft Master Certification
- Use SqlConnection With LINQ To SQL
- Free Icons And Images With Visual Studio 2008
- Capture XML In WCF Service
- Dynamic Sort With LINQ
- StyleCop Tutorial
Tags
.Net 2010 ADO.NET ASP.NET Azure Blogging Books Browsers C# Certification Cloud Computing Code Snippets Community Data Services Eclipse Entity Framework Google IDE Java LINQ Mac Microsoft Museum NetBeans Office Oracle REST SharePoint Silverlight SQL Server T-SQL Tips Tools Training Visual Studio Visual Studio 2010 WCF Web Windows Windows 7 Windows Forms Windows Live WMI WPF XAML

