Java Timestamp Now currentTimestamp()

Here you can find the source of currentTimestamp()

Description

current Timestamp

License

Apache License

Declaration

public static String currentTimestamp() 

Method Source Code

//package com.java2s;
/**/*w w  w.  j  a v  a  2 s.  co m*/
 * Copyright (c) 2005-2009 springside.org.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * 
 * $Id: NonceUtils.java 762 2009-12-27 14:46:36Z calvinxiu $
 */

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    private static final SimpleDateFormat INTERNATE_DATE_FORMAT = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    private static final String[] SPACES = { "0", "00", "0000", "00000000" };

    public static String currentTimestamp() {
        Date now = new Date();
        return INTERNATE_DATE_FORMAT.format(now);
    }

    public static String format(String source, int length) {
        int spaceLength = length - source.length();
        StringBuilder buf = new StringBuilder();

        while (spaceLength >= 8) {
            buf.append(SPACES[3]);
            spaceLength -= 8;
        }

        for (int i = 2; i >= 0; i--) {
            if ((spaceLength & (1 << i)) != 0) {
                buf.append(SPACES[i]);
            }
        }

        buf.append(source);
        return buf.toString();
    }
}

Related

  1. currentTimeStamp()
  2. currentTimestamp()
  3. currentTimeStamp()
  4. currentTimeStamp()
  5. currentTimestamp()