Java Now now()

Here you can find the source of now()

Description

now

License

Apache License

Return

display the current Date

Declaration

public static String now() 

Method Source Code

//package com.java2s;
/** /* w w  w. jav  a  2 s  .c  o m*/
 * UIMA Common
 * Copyright (C) 2010  Nicolas Hernandez
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";

    /**
     * 
     * @return display the current Date
     * 
     */
    public static String now() {
        Calendar cal = Calendar.getInstance();

        return stringFormatADate(Calendar.getInstance().getTime());
        // formats
        //       System.out.println(DateUtils.now("dd MMMMM yyyy"));
        //        System.out.println(DateUtils.now("yyyyMMdd"));
        //        System.out.println(DateUtils.now("dd.MM.yy"));
        //        System.out.println(DateUtils.now("MM/dd/yy"));
        //        System.out.println(DateUtils.now("yyyy.MM.dd G 'at' hh:mm:ss z"));
        //        System.out.println(DateUtils.now("EEE, MMM d, ''yy"));
        //        System.out.println(DateUtils.now("h:mm a"));
        //        System.out.println(DateUtils.now("H:mm:ss:SSS"));
        //        System.out.println(DateUtils.now("K:mm a,z"));
        //        System.out.println(DateUtils.now("yyyy.MMMMM.dd GGG hh:mm aaa"));
    }

    /**
     * 
     * @return a Date as a formatted String
     * 
     */
    public static String stringFormatADate(Date aDate) {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);

        return sdf.format(aDate.getTime());
        // formats
        //       System.out.println(DateUtils.now("dd MMMMM yyyy"));
        //        System.out.println(DateUtils.now("yyyyMMdd"));
        //        System.out.println(DateUtils.now("dd.MM.yy"));
        //        System.out.println(DateUtils.now("MM/dd/yy"));
        //        System.out.println(DateUtils.now("yyyy.MM.dd G 'at' hh:mm:ss z"));
        //        System.out.println(DateUtils.now("EEE, MMM d, ''yy"));
        //        System.out.println(DateUtils.now("h:mm a"));
        //        System.out.println(DateUtils.now("H:mm:ss:SSS"));
        //        System.out.println(DateUtils.now("K:mm a,z"));
        //        System.out.println(DateUtils.now("yyyy.MMMMM.dd GGG hh:mm aaa"));
    }
}

Related

  1. now()
  2. now()
  3. now()
  4. now()
  5. now()
  6. now()
  7. now()
  8. now()
  9. Now()