1 /*
2 * Copyright 2014-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15 package com.amazonaws.auth.internal;
16
17 import org.joda.time.format.DateTimeFormat;
18 import org.joda.time.format.DateTimeFormatter;
19
20 /**
21 * Utility methods that is used by the different AWS Signer implementations.
22 * This class is strictly internal and is subjected to change.
23 */
24 public final class AWS4SignerUtils {
25
26 private static final DateTimeFormatter dateFormatter = DateTimeFormat
27 .forPattern("yyyyMMdd").withZoneUTC();
28
29 private static final DateTimeFormatter timeFormatter = DateTimeFormat
30 .forPattern("yyyyMMdd'T'HHmmss'Z'").withZoneUTC();
31
32 /**
33 * Returns a string representation of the given date time in yyyyMMdd
34 * format. The date returned is in the UTC zone.
35 *
36 * For example, given a time "1416863450581", this method returns "20141124"
37 */
38 public static String formatDateStamp(long timeMilli) {
39 return dateFormatter.print(timeMilli);
40 }
41
42 /**
43 * Returns a string representation of the given date time in
44 * yyyyMMdd'T'HHmmss'Z' format. The date returned is in the UTC zone.
45 *
46 * For example, given a time "1416863450581", this method returns
47 * "20141124T211050Z"
48 */
49 public static String formatTimestamp(long timeMilli) {
50 return timeFormatter.print(timeMilli);
51 }
52 }
53