1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.documentsui.inspector;
17 
18 import android.content.Context;
19 import android.content.res.Resources;
20 import android.text.format.DateFormat;
21 
22 import com.android.documentsui.R;
23 
24 import java.util.Locale;
25 
26 /**
27  * Helper methods for dealing with dates.
28  */
29 final class DateUtils {
30     /**
31      * This small helper method combines two different DateFormat subclasses in order to format
32      * both the date and the time based on user locale.
33      * @param date Unix timestamp
34      * @return formatted String of date
35      */
formatDate(Context context, long date)36     static String formatDate(Context context, long date) {
37         Resources res = context.getResources();
38         int formatRes = DateFormat.is24HourFormat(context)
39                 ? R.string.datetime_format_24
40                 : R.string.datetime_format_12;
41         String format = DateFormat.getBestDateTimePattern(
42                 Locale.getDefault(),
43                 res.getString(formatRes));
44         return DateFormat.format(format, date).toString();
45     }
46 }
47