Java String to Date toDateTimeFormat(String input, String inputfmt, String outputfmt)

Here you can find the source of toDateTimeFormat(String input, String inputfmt, String outputfmt)

Description

to Date Time Format

License

Open Source License

Declaration

public static String toDateTimeFormat(String input, String inputfmt, String outputfmt) 

Method Source Code


//package com.java2s;
/*//from  w w  w. j  a va2  s.  c om
 * Copyright (C) 2014-2016 LinkedIn Corp. All rights reserved.
 *
 * 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.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String toDateTimeFormat(String input, String inputfmt, String outputfmt) {
        Date date = null;
        SimpleDateFormat infmt = new SimpleDateFormat(inputfmt);
        try {
            date = infmt.parse(input);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        SimpleDateFormat outFormat = new SimpleDateFormat(outputfmt);
        return outFormat.format(date);
    }
}

Related

  1. toDateString(long lval)
  2. toDateString(long ms)
  3. toDateString(String fmt, Date date)
  4. toDateStyleBoth(String dateStr)
  5. toDatetime(String sDate)
  6. toDateTimeSSSString(long datetime)
  7. toDateTimeString(java.util.Date date)
  8. toDateTimeString(java.util.Date date)
  9. toDateWithFormatString(String date, String format)