Java timestamp generation

Source: Internet
Author: User
Package CN. mldn. lxh. util; import Java. text. simpledateformat; import Java. util. date; import Java. util. random; public class iptimestamp {private simpledateformat SDF = NULL; private string IP = NULL; Public iptimestamp () {} public iptimestamp (string IP) {This. IP = IP;} Public String getiptimerand () {stringbuffer Buf = new stringbuffer (); If (this. IP address! = NULL) {string s [] = This. IP. split ("\\. "); For (INT I = 0; I <S. length; I ++) {Buf. append (this. addzero (s [I], 3); // Add 0} Buf if there are not three digits. append (this. gettimestamp (); // obtain the time stamp random r = new random (); For (INT I = 0; I <3; I ++) {Buf. append (R. nextint (10); // Add a random number} return Buf. tostring ();} private string addzero (string STR, int Len) {stringbuffer S = new stringbuffer (); S. append (STR); While (S. length () <Len) {S. insert (0, "0");} return S. tostring ();} Public String getdate () {This. SDF = new simpledateformat ("yyyy-mm-dd hh: mm: Ss. SSS "); return this. SDF. format (new date ();} Public String gettimestamp () {This. SDF = new simpledateformat ("yyyymmddhhmmsssss"); return this. SDF. format (new date ());}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.