Here you can find the source of parse(String input)
Parameter | Description |
---|---|
input | a parameter |
public static Date parse(String input)
//package com.java2s; /*/*from w ww . j a v a2s .c o m*/ * Author Stephen Booysen * * Copyright (c) 2015 Stephen Booysen, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of * Stephen Booysen. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Stephen Booysen * * Stephen Booysen MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * Try and evaluate the string and return a date * * @param input * @return */ public static Date parse(String input) { try { return new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(input); } catch (Exception e) { } try { return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(input); } catch (Exception e) { } try { return new SimpleDateFormat("yyyy-MM-dd").parse(input); } catch (Exception e) { } try { return new SimpleDateFormat("yyyy/MM/dd").parse(input); } catch (Exception e) { } try { return new SimpleDateFormat("dd MMM yyyy").parse(input); } catch (Exception e) { } try { return new SimpleDateFormat("dow mon dd hh:mm:ss zzz yyyy").parse(input); } catch (Exception e) { } try { return new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy").parse(input); } catch (Exception e) { } try { return new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy").parse(input); } catch (Exception e) { } return null; } /** * Try to evaluate a date and return a string * * @param input * @return */ public static String parse(Date input) { try { return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(input); } catch (Exception e) { } try { return new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(input); } catch (Exception e) { } return null; } /** * Try to evaluate a date and return a string * * @param input * @return */ public static String parse(Date input, String format) { try { return new SimpleDateFormat(format).format(input); } catch (Exception e) { } return null; } }