Java DateTimeFormatter getTime(String format)

Here you can find the source of getTime(String format)

Description

get Time

License

Apache License

Declaration

public static String getTime(String format) 

Method Source Code


//package com.java2s;
/*// w  ww  .j a  va 2s .c om
 *   Copyright 2015 ?ubom?r Hlavko
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.time.LocalDateTime;

public class Main {
    public static String getTime() {
        return getTime("%d-%d-%d %d-%d-%d");
    }

    public static String getTime(String format) {
        LocalDateTime dt = LocalDateTime.now();
        return String.format(format, dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(), dt.getHour(),
                dt.getMinute(), dt.getSecond());
    }
}

Related

  1. getPreferredDateFormat()
  2. getShortDateManualEntryFormatter()
  3. getShortFormatter(Locale locale)
  4. getStartOfDay(Date dateToFormat)
  5. getTime(final String time, final DateTimeFormatter formatter)
  6. getTimeFromEpochMilli(String value, boolean shortFormat, String errorText)
  7. getTimeStamp(final String dateTimeFormatPattern)
  8. getTimestampedPath(Path baseFile, TemporalAccessor time, DateTimeFormatter formatter)
  9. parse(DateTimeFormatter formatter, String string)