How can I get the current date and time in UTC or GMT in Java?

JavaDateLocalizationTimezoneGmt

Java Problem Overview


When I create a new Date object, it is initialized to the current time but in the local timezone. How can I get the current date and time in GMT?

Java Solutions


Solution 1 - Java

tl;dr

Instant.now()   // Capture the current moment in UTC. 

Generate a String to represent that value:

Instant.now().toString()  

>2016-09-13T23:30:52.123Z

Details

As the correct answer by Jon Skeet stated, a java.util.Date object has no time zone. But its toString implementation applies the JVM’s default time zone when generating the String representation of that date-time value. Confusingly to the naïve programmer, a Date seems to have a time zone but does not.

The java.util.Date, j.u.Calendar, and java.text.SimpleDateFormat classes bundled with Java are notoriously troublesome. Avoid them. Instead, use either of these competent date-time libraries:

java.time (Java 8)

Java 8 brings an excellent new java.time.* package to supplant the old java.util.Date/Calendar classes.

Getting current time in UTC/GMT is a simple one-liner…

Instant instant = Instant.now();

That Instant class is the basic building block in java.time, representing a moment on the timeline in UTC with a resolution of nanoseconds.

In Java 8, the current moment is captured with only up to milliseconds resolution. Java 9 brings a fresh implementation of Clock captures the current moment in up to the full nanosecond capability of this class, depending on the ability of your host computer’s clock hardware.

It’s toString method generates a String representation of its value using one specific ISO 8601 format. That format outputs zero, three, six or nine digits digits (milliseconds, microseconds, or nanoseconds) as necessary to represent the fraction-of-second.

If you want more flexible formatting, or other additional features, then apply an offset-from-UTC of zero, for UTC itself (ZoneOffset.UTC constant) to get a OffsetDateTime.

OffsetDateTime now = OffsetDateTime.now( ZoneOffset.UTC );

Dump to console…

System.out.println( "now.toString(): " + now );

When run…

now.toString(): 2014-01-21T23:42:03.522Z

https://i.stack.imgur.com/MZe55.png" alt="Table of date-time types in Java, both modern and legacy." />


About java.time

The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.

To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.

The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.

You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.* classes.

Where to obtain the java.time classes?

Table of which java.time library to use with which version of Java or Android

The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.


Joda-Time

UPDATE: The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.

Using the Joda-Time 3rd-party open-source free-of-cost library, you can get the current date-time in just one line of code.

Joda-Time inspired the new java.time.* classes in Java 8, but has a different architecture. You may use Joda-Time in older versions of Java. Joda-Time continues to work in Java 8 and continues to be actively maintained (as of 2014). However, the Joda-Time team does advise migration to java.time.

System.out.println( "UTC/GMT date-time in ISO 8601 format: " + new org.joda.time.DateTime( org.joda.time.DateTimeZone.UTC ) );

More detailed example code (Joda-Time 2.3)…

org.joda.time.DateTime now = new org.joda.time.DateTime(); // Default time zone.
org.joda.time.DateTime zulu = now.toDateTime( org.joda.time.DateTimeZone.UTC );

Dump to console…

System.out.println( "Local time in ISO 8601 format: " + now );
System.out.println( "Same moment in UTC (Zulu): " + zulu );

When run…

Local time in ISO 8601 format: 2014-01-21T15:34:29.933-08:00
Same moment in UTC (Zulu): 2014-01-21T23:34:29.933Z

For more example code doing time zone work, see my answer to a similar question.

Time Zone

I recommend you always specify a time zone rather than relying implicitly on the JVM’s current default time zone (which can change at any moment!). Such reliance seems to be a common cause of confusion and bugs in date-time work.

When calling now() pass the desired/expected time zone to be assigned. Use the DateTimeZone class.

DateTimeZone zoneMontréal = DateTimeZone.forID( "America/Montreal" );
DateTime now = DateTime.now( zoneMontréal );

That class holds a constant for UTC time zone.

DateTime now = DateTime.now( DateTimeZone.UTC );

If you truly want to use the JVM’s current default time zone, make an explicit call so your code is self-documenting.

DateTimeZone zoneDefault = DateTimeZone.getDefault();

ISO 8601

Read about ISO 8601 formats. Both java.time and Joda-Time use that standard’s sensible formats as their defaults for both parsing and generating strings.


Actually, java.util.Date does have a time zone, buried deep under layers of source code. For most practical purposes, that time zone is ignored. So, as shorthand, we say java.util.Date has no time zone. Furthermore, that buried time zone is not the one used by Date’s toString method; that method uses the JVM’s current default time zone. All the more reason to avoid this confusing class and stick with Joda-Time and java.time.

Solution 2 - Java

java.util.Date has no specific time zone, although its value is most commonly thought of in relation to UTC. What makes you think it's in local time?

To be precise: the value within a java.util.Date is the number of milliseconds since the Unix epoch, which occurred at midnight January 1st 1970, UTC. The same epoch could also be described in other time zones, but the traditional description is in terms of UTC. As it's a number of milliseconds since a fixed epoch, the value within java.util.Date is the same around the world at any particular instant, regardless of local time zone.

I suspect the problem is that you're displaying it via an instance of Calendar which uses the local timezone, or possibly using Date.toString() which also uses the local timezone, or a SimpleDateFormat instance, which, by default, also uses local timezone.

If this isn't the problem, please post some sample code.

I would, however, recommend that you use Joda-Time anyway, which offers a much clearer API.

Solution 3 - Java

SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));

//Local time zone	
SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");

//Time in GMT
return dateFormatLocal.parse( dateFormatGmt.format(new Date()) );

Solution 4 - Java

This definitely returns UTC time: as String and Date objects !

static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

public static Date getUTCdatetimeAsDate() {
	// note: doesn't check for null
	return stringDateToDate(getUTCdatetimeAsString());
}

public static String getUTCdatetimeAsString() {
	final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
	sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
	final String utcTime = sdf.format(new Date());
	
	return utcTime;
}

public static Date stringDateToDate(String StrDate) {
	Date dateToReturn = null;
	SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT);
	
	try {
		dateToReturn = (Date)dateFormat.parse(StrDate);
	}
	catch (ParseException e) {
		e.printStackTrace();
	}
	
	return dateToReturn;
}

Solution 5 - Java

	Calendar c = Calendar.getInstance();
	System.out.println("current: "+c.getTime());

	TimeZone z = c.getTimeZone();
	int offset = z.getRawOffset();
	if(z.inDaylightTime(new Date())){
		offset = offset + z.getDSTSavings();
	}
	int offsetHrs = offset / 1000 / 60 / 60;
	int offsetMins = offset / 1000 / 60 % 60;

	System.out.println("offset: " + offsetHrs);
	System.out.println("offset: " + offsetMins);

	c.add(Calendar.HOUR_OF_DAY, (-offsetHrs));
	c.add(Calendar.MINUTE, (-offsetMins));

	System.out.println("GMT Time: "+c.getTime());

Solution 6 - Java

Actually not time, but it's representation could be changed.

SimpleDateFormat f = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
f.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(f.format(new Date()));

Time is the same in any point of the Earth, but our perception of time could be different depending on location.

Solution 7 - Java

> Calendar aGMTCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); Then all operations performed using the aGMTCalendar object will be done with the GMT time zone and will not have the daylight savings time or fixed offsets applied

Wrong!

Calendar aGMTCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
aGMTCalendar.getTime(); //or getTimeInMillis()

and

Calendar aNotGMTCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT-2"));aNotGMTCalendar.getTime();

will return the same time. Idem for

new Date(); //it's not GMT.

Solution 8 - Java

This works for getting UTC milliseconds in Android.

Calendar c = Calendar.getInstance();
int utcOffset = c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET);  
Long utcMilliseconds = c.getTimeInMillis() + utcOffset;

Solution 9 - Java

This code prints the current time UTC.

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;


public class Test
{
	public static void main(final String[] args) throws ParseException
	{
		final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
		f.setTimeZone(TimeZone.getTimeZone("UTC"));
		System.out.println(f.format(new Date()));
	}
}

Result

2013-10-26 14:37:48 UTC

Solution 10 - Java

Here is what seems to be incorrect in Jon Skeet's answer. He said:

> java.util.Date is always in UTC. What makes you think it's in local > time? I suspect the problem is that you're displaying it via an > instance of Calendar which uses the local timezone, or possibly using > Date.toString() which also uses the local timezone.

However, the code:

System.out.println(new java.util.Date().getHours() + " hours");

gives the local hours, not GMT (UTC hours), using no Calendar and no SimpleDateFormat at all.

That is why is seems something is incorrect.

Putting together the responses, the code:

System.out.println(Calendar.getInstance(TimeZone.getTimeZone("GMT"))
                           .get(Calendar.HOUR_OF_DAY) + " Hours");

shows the GMT hours instead of the local hours -- note that getTime.getHours() is missing because that would create a Date() object, which theoretically stores the date in GMT, but gives back the hours in the local time zone.

Solution 11 - Java

If you want a Date object with fields adjusted for UTC you can do it like this with Joda Time:

import org.joda.time.DateTimeZone;
import java.util.Date;

...

Date local = new Date();
System.out.println("Local: " + local);
DateTimeZone zone = DateTimeZone.getDefault();
long utc = zone.convertLocalToUTC(local.getTime(), false);
System.out.println("UTC: " + new Date(utc));

Solution 12 - Java

You can use:

Calendar aGMTCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

Then all operations performed using the aGMTCalendar object will be done with the GMT time zone and will not have the daylight savings time or fixed offsets applied. I think the previous poster is correct that the Date() object always returns a GMT it's not until you go to do something with the date object that it gets converted to the local time zone.

Solution 13 - Java

SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd");
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(dateFormatGmt.format(date));

Solution 14 - Java

You can directly use this

SimpleDateFormat dateFormatGmt = new SimpleDateFormat("dd:MM:yyyy HH:mm:ss");
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(dateFormatGmt.format(new Date())+"");

Solution 15 - Java

Here is my implementation of toUTC:

    public static Date toUTC(Date date){
    long datems = date.getTime();
    long timezoneoffset = TimeZone.getDefault().getOffset(datems);
    datems -= timezoneoffset;
    return new Date(datems);
}

There's probably several ways to improve it, but it works for me.

Solution 16 - Java

Here an other suggestion to get a GMT Timestamp object:

import java.sql.Timestamp;
import java.util.Calendar;

...

private static Timestamp getGMT() {
   Calendar cal = Calendar.getInstance();
   return new Timestamp(cal.getTimeInMillis()
                       -cal.get(Calendar.ZONE_OFFSET)
                       -cal.get(Calendar.DST_OFFSET));
}

Solution 17 - Java

Here is another way to get GMT time in String format

String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss z" ;
final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String dateTimeString =  sdf.format(new Date());

Solution 18 - Java

With:

Calendar cal = Calendar.getInstance();

Then cal have the current date and time.
You also could get the current Date and Time for timezone with:

Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("GMT-2"));

You could ask cal.get(Calendar.DATE); or other Calendar constant about others details.
Date and Timestamp are deprecated in Java. Calendar class it isn't.

Solution 19 - Java

Sample code to render system time in a specific time zone and a specific format.

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class TimZoneTest {
    public static void main (String[] args){
        //<GMT><+/-><hour>:<minutes>
        // Any screw up in this format, timezone defaults to GMT QUIETLY. So test your format a few times.

        System.out.println(my_time_in("GMT-5:00", "MM/dd/yyyy HH:mm:ss") );
        System.out.println(my_time_in("GMT+5:30", "'at' HH:mm a z 'on' MM/dd/yyyy"));
        
        System.out.println("---------------------------------------------");
        // Alternate format 
        System.out.println(my_time_in("America/Los_Angeles", "'at' HH:mm a z 'on' MM/dd/yyyy") );
        System.out.println(my_time_in("America/Buenos_Aires", "'at' HH:mm a z 'on' MM/dd/yyyy") );


    }

    public static String my_time_in(String target_time_zone, String format){
        TimeZone tz = TimeZone.getTimeZone(target_time_zone);
        Date date = Calendar.getInstance().getTime();
        SimpleDateFormat date_format_gmt = new SimpleDateFormat(format);
        date_format_gmt.setTimeZone(tz);
        return date_format_gmt.format(date);
    }

}

Output

10/08/2011 21:07:21
at 07:37 AM GMT+05:30 on 10/09/2011
at 19:07 PM PDT on 10/08/2011
at 23:07 PM ART on 10/08/2011

Solution 20 - Java

Just to make this simpler, to create a Date in UTC you can use Calendar :

Calendar.getInstance(TimeZone.getTimeZone("UTC"));

Which will construct a new instance for Calendar using the "UTC" TimeZone.

If you need a Date object from that calendar you could just use getTime().

Solution 21 - Java

Converting Current DateTime in UTC:

DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

DateTimeZone dateTimeZone = DateTimeZone.getDefault(); //Default Time Zone

DateTime currDateTime = new DateTime(); //Current DateTime

long utcTime = dateTimeZone.convertLocalToUTC(currDateTime .getMillis(), false);

String currTime = formatter.print(utcTime); //UTC time converted to string from long in format of formatter

currDateTime = formatter.parseDateTime(currTime); //Converted to DateTime in UTC

Solution 22 - Java

public static void main(String args[]){
    LocalDate date=LocalDate.now();  
    System.out.println("Current date = "+date);
}

Solution 23 - Java

This worked for me, returns the timestamp in GMT!

    Date currDate;
	SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
	dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
	SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
	
	long currTime = 0;
	try {

		currDate = dateFormatLocal.parse( dateFormatGmt.format(new Date()) );
		currTime = currDate.getTime();
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

Solution 24 - Java

The Simple Function that you can use:

Edit: this version uses the modern java.time classes.

private static final DateTimeFormatter FORMATTER
		= DateTimeFormatter.ofPattern("dd-MM-uuuu HH:mm:ss z");

public static String getUtcDateTime() {
    return ZonedDateTime.now(ZoneId.of("Etc/UTC")).format(FORMATTER);
}

Return value from the method:

26-03-2022 17:38:55 UTC

Original function:

 public String getUTC_DateTime() {
    SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss z");
    dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));//gmt
    return dateTimeFormat.format(new Date());

}

return of above function:

26-03-2022 08:07:21 UTC 

Solution 25 - Java

To put it simple. A calendar object stores information about time zone but when you perform cal.getTime() then the timezone information will be lost. So for Timezone conversions I will advice to use DateFormat classes...

Solution 26 - Java

Use this Class to get ever the right UTC Time from a Online NTP Server:

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;


class NTP_UTC_Time
{
private static final String TAG = "SntpClient";

private static final int RECEIVE_TIME_OFFSET = 32;
private static final int TRANSMIT_TIME_OFFSET = 40;
private static final int NTP_PACKET_SIZE = 48;

private static final int NTP_PORT = 123;
private static final int NTP_MODE_CLIENT = 3;
private static final int NTP_VERSION = 3;

// Number of seconds between Jan 1, 1900 and Jan 1, 1970
// 70 years plus 17 leap days
private static final long OFFSET_1900_TO_1970 = ((365L * 70L) + 17L) * 24L * 60L * 60L;

private long mNtpTime;

public boolean requestTime(String host, int timeout) {
    try {
        DatagramSocket socket = new DatagramSocket();
        socket.setSoTimeout(timeout);
        InetAddress address = InetAddress.getByName(host);
        byte[] buffer = new byte[NTP_PACKET_SIZE];
        DatagramPacket request = new DatagramPacket(buffer, buffer.length, address, NTP_PORT);

        buffer[0] = NTP_MODE_CLIENT | (NTP_VERSION << 3);

        writeTimeStamp(buffer, TRANSMIT_TIME_OFFSET);

        socket.send(request);

        // read the response
        DatagramPacket response = new DatagramPacket(buffer, buffer.length);
        socket.receive(response);          
        socket.close();
   
        mNtpTime = readTimeStamp(buffer, RECEIVE_TIME_OFFSET);            
    } catch (Exception e) {
      //  if (Config.LOGD) Log.d(TAG, "request time failed: " + e);
        return false;
    }

    return true;
}


public long getNtpTime() {
    return mNtpTime;
}


/**
 * Reads an unsigned 32 bit big endian number from the given offset in the buffer.
 */
private long read32(byte[] buffer, int offset) {
    byte b0 = buffer[offset];
    byte b1 = buffer[offset+1];
    byte b2 = buffer[offset+2];
    byte b3 = buffer[offset+3];

    // convert signed bytes to unsigned values
    int i0 = ((b0 & 0x80) == 0x80 ? (b0 & 0x7F) + 0x80 : b0);
    int i1 = ((b1 & 0x80) == 0x80 ? (b1 & 0x7F) + 0x80 : b1);
    int i2 = ((b2 & 0x80) == 0x80 ? (b2 & 0x7F) + 0x80 : b2);
    int i3 = ((b3 & 0x80) == 0x80 ? (b3 & 0x7F) + 0x80 : b3);

    return ((long)i0 << 24) + ((long)i1 << 16) + ((long)i2 << 8) + (long)i3;
}

/**
 * Reads the NTP time stamp at the given offset in the buffer and returns 
 * it as a system time (milliseconds since January 1, 1970).
 */    
private long readTimeStamp(byte[] buffer, int offset) {
    long seconds = read32(buffer, offset);
    long fraction = read32(buffer, offset + 4);
    return ((seconds - OFFSET_1900_TO_1970) * 1000) + ((fraction * 1000L) / 0x100000000L);        
}

/**
 * Writes 0 as NTP starttime stamp in the buffer. --> Then NTP returns Time OFFSET since 1900
 */    
private void writeTimeStamp(byte[] buffer, int offset) {    	
	int ofs =  offset++;
	
	for (int i=ofs;i<(ofs+8);i++)
	  buffer[i] = (byte)(0);             
}
              
}

And use it with:

        long now = 0;

        NTP_UTC_Time client = new NTP_UTC_Time();

        if (client.requestTime("pool.ntp.org", 2000)) {              
          now = client.getNtpTime();
        }

If you need UTC Time "now" as DateTimeString use function:

private String get_UTC_Datetime_from_timestamp(long timeStamp){

	try{
		
		Calendar cal = Calendar.getInstance();
  		TimeZone tz = cal.getTimeZone();
  		
  		int tzt = tz.getOffset(System.currentTimeMillis());
  			  			  		
  		timeStamp -= tzt;
		
	    // DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.getDefault());
	    DateFormat sdf = new SimpleDateFormat();
	    Date netDate = (new Date(timeStamp));
	    return sdf.format(netDate);
	}
	catch(Exception ex){
	    return "";
	 }
	} 

and use it with:

String UTC_DateTime = get_UTC_Datetime_from_timestamp(now);

Solution 27 - Java

this is my implementation:

public static String GetCurrentTimeStamp()
{
	Calendar cal=Calendar.getInstance();
	long offset = cal.getTimeZone().getOffset(System.currentTimeMillis());//if you want in UTC else remove it .
	return new java.sql.Timestamp(System.currentTimeMillis()+offset).toString();	
}

Solution 28 - Java

If you want to avoid parsing the date and just want a timestamp in GMT, you could use:

final Date gmt = new Timestamp(System.currentTimeMillis()
			- Calendar.getInstance().getTimeZone()
					.getOffset(System.currentTimeMillis()));

Solution 29 - Java

public class CurrentUtcDate 
{
	public static void main(String[] args) {
		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
		dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
		System.out.println("UTC Time is: " + dateFormat.format(date));
	}
}
 

Output:

UTC Time is: 22-01-2018 13:14:35

You can change the date format as needed.

Solution 30 - Java

Current date in the UTC

Instant.now().toString().replaceAll("T.*", "");

Solution 31 - Java

If you're using joda time and want the current time in milliseconds without your local offset you can use this:

long instant = DateTimeZone.UTC.getMillisKeepLocal(DateTimeZone.getDefault(), System.currentTimeMillis());

Solution 32 - Java

Use java.time package and include below code-

ZonedDateTime now = ZonedDateTime.now( ZoneOffset.UTC );

or

LocalDateTime now2 = LocalDateTime.now( ZoneOffset.UTC );

depending on your application need.

Solution 33 - Java

This is the way I do it when I need to output a Date object, which is usually the case when you need to save a Date in an SQL database and I want it to be in UTC. I just subtract the offset time of the local time zone.

    ZonedDateTime now = ZonedDateTime.now();
    Date nowUTC = new Date(1000 * (now.toEpochSecond() - now.getOffset().getTotalSeconds()));

--UPDATE Basil's suggestion for a cleaner way to have the same result would be

    Date nowUTC = Date.from(ZonedDateTime.now().toInstant());

BUT after testing this in a non-UTC java system env, I saw that the results are not the same. With Basil's code, the Date is still on local zone

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBehrangView Question on Stackoverflow
Solution 1 - JavaBasil BourqueView Answer on Stackoverflow
Solution 2 - JavaJon SkeetView Answer on Stackoverflow
Solution 3 - JavaDanView Answer on Stackoverflow
Solution 4 - JavaSomeone SomewhereView Answer on Stackoverflow
Solution 5 - JavaAhmad NadeemView Answer on Stackoverflow
Solution 6 - JavaAntonioView Answer on Stackoverflow
Solution 7 - JavasimpaticoView Answer on Stackoverflow
Solution 8 - JavamobermeView Answer on Stackoverflow
Solution 9 - JavaAdamView Answer on Stackoverflow
Solution 10 - JavaDana WilsonView Answer on Stackoverflow
Solution 11 - JavahuljasView Answer on Stackoverflow
Solution 12 - Javamjh2007View Answer on Stackoverflow
Solution 13 - JavaJustinView Answer on Stackoverflow
Solution 14 - JavanithinreddyView Answer on Stackoverflow
Solution 15 - JavaAshallarView Answer on Stackoverflow
Solution 16 - JavaReneView Answer on Stackoverflow
Solution 17 - JavashahtapaView Answer on Stackoverflow
Solution 18 - Javauser2427View Answer on Stackoverflow
Solution 19 - Javaso_mvView Answer on Stackoverflow
Solution 20 - JavaOvidiu LatcuView Answer on Stackoverflow
Solution 21 - JavaMy GodView Answer on Stackoverflow
Solution 22 - JavaArjun SinghView Answer on Stackoverflow
Solution 23 - JavaBogdanView Answer on Stackoverflow
Solution 24 - JavaAmmarView Answer on Stackoverflow
Solution 25 - JavaHiteshView Answer on Stackoverflow
Solution 26 - JavaIngoView Answer on Stackoverflow
Solution 27 - JavaGal RomView Answer on Stackoverflow
Solution 28 - JavaMatthias van der VliesView Answer on Stackoverflow
Solution 29 - JavasantoshlokhandeView Answer on Stackoverflow
Solution 30 - JavaArefeView Answer on Stackoverflow
Solution 31 - JavaManagarmView Answer on Stackoverflow
Solution 32 - JavaAsifView Answer on Stackoverflow
Solution 33 - JavaJohnPanView Answer on Stackoverflow