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:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>