yegor256
yegor256

Reputation: 105063

which timezone is used by DateUtils?

I'm trying to use DateUtils from apache-commons3, but can't understand which timezone it relies on:

Date date = DateUtils.truncate(date, Calendar.DATE);

How does it know which timezone I'm in?

Upvotes: 3

Views: 2761

Answers (1)

Daniel Kaplan
Daniel Kaplan

Reputation: 67360

The timezone which is the default of your computer. Looking at the source code, it does this:

    public static Date truncate(Date date, int field) {
        if (date == null) {
            throw new IllegalArgumentException("The date must not be null");
        }
        Calendar gval = Calendar.getInstance();
        gval.setTime(date);
        modify(gval, field, MODIFY_TRUNCATE);
        return gval.getTime();
    }

The documentation of Calendar.getInstance() says: Gets a calendar using the default time zone and locale.

If you're willing to switch to JodaTime instead, here's a way do the same thing in JodaTime: JodaTime equivalent of DateUtils.truncate()

Upvotes: 5

Related Questions