java如何实现各国时间格式转换成yyyy-MM-dd HH:mm:ss时间格式?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java如何实现各国时间格式转换成yyyy-MM-dd HH:mm:ss时间格式?相关的知识,希望对你有一定的参考价值。

如题:比如:Mon 25.08.2014 18:17 还有August 16, 2014 , 7:46 am

等等,急急急....

SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒");
Date d = new Date();
String timeStr = sdf1.format(d)//结果就是这种格式:2014-08-08 08:08:20
String timeStr2 = sdf2.format(d)//结果就是这种格式:2014年08月08日 08时08分20秒

参考技术A 不管是哪个国家的, 只要是java.util.Date, 就可以使用 new SimpleDateFormat("yyyy-MM-dd").format(new Date())来格式化本回答被提问者采纳 参考技术B public static void main(String[] args) throws ParseException
SimpleDateFormat sdf1=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
SimpleDateFormat sdf2=new SimpleDateFormat("yyyy/MM/dd HH:mm");
SimpleDateFormat sdf3=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date now=new Date();

// System.out.println(sdf1.format(now));
// System.out.println(sdf2.format(now));
// System.out.println(sdf3.format(now));

String d="2014-06-01 21:05:06";
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date date = sdf3.parse(d);
System.out.println(date);

参考技术C * 将日期对象转换为字符串格式
*/

Date date = new Date();
//自己创建的自定义的格式化对象。
DateFormat dateformat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss"
);

//调用格式对象中的格式方法,将日期对象转换为字符串
System.out.println(dateformat.format(date));
参考技术D SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

RSA的密钥把JAVA格式转换成C#的格式

把C#格式转换成Java:RSA的密钥把JAVA格式转换成C#的格式(1)

我已经在第一篇介绍过如何把C#格式转换成Java,现在来看看如何把Java格式转换成C#。

 /// <summary>
        /// RSA加密
        /// </summary>
        /// <param name="publickey"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public string RSAEncrypt(string publickey, string content)
        {
            publickey = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/M9kJVwi+sO672NBm5fAEbUEl2PqRFuYZVB5ZrKah7eJPP0pKBe/eoA6pOMsjnKFoZGVizz7oCt+TJ+1fpuScn7vAtIFSjn1jgPANE+IcVdk4QKDFKu0LQdiurPQKLpq8Q3wJDAW7FxB2MHw/4ca/9w0N5VL0hQegZ4YhxDss6QIDAQABprivateKey";
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            byte[] cipherbytes;
            rsa.FromXmlString(publickey);
            cipherbytes = rsa.Encrypt(Encoding.UTF8.GetBytes(content), false);

            return Convert.ToBase64String(cipherbytes);
        }

        /// <summary>
        /// RSA解密
        /// </summary>
        /// <param name="privatekey"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public string RSADecrypt(string content)
        {
            //私钥
            string NET_PRIVATE_KEY = @"<RSAKeyValue><Modulus>vzPZCVcIvrDuu9jQZuXwBG1BJdj6kRbmGVQeWaymoe3iTz9KSgXv3qAOqTjLI5yhaGRlYs8+6ArfkyftX6bknJ+7wLSBUo59Y4DwDRPiHFXZOECgxSrtC0HYrqz0Ci6avEN8CQwFuxcQdjB8P+HGv/cNDeVS9IUHoGeGIcQ7LOk=</Modulus><Exponent>AQAB</Exponent><P>81Hqu5RXCBOLloURr3lRYzQBrkrFvqvRjsDu7UuWMLgCENjPl4GBkRaPMTAulf/Un6ibZklNc5O9qTJWLnyKhw==</P><Q>ySqkcKbWuobq5I9KSQISq2qCuGKtj/iUFho4PCD1YxhnQ7gcHA4OpS1dRFjtXJYQPTX9be+mmypsCFIyofE5Dw==</Q><DP>8ZnbTBqFOH2/0tuarfP2flx7dsbEBwmwcODd3T16ijGLy5KcvkFXl+sgj6TZ/RMj2syeUThj8Wk3n7Ndo5cCLQ==</DP><DQ>rNwKn46Nt4yVrT7/y0qPtmJ4325TzAIDZhazud9sXPGsUoGTDfx6Uy9vFHsBw+xjGeYZ1mz3EiBa4q+XOJbquw==</DQ><InverseQ>i90WdnZVPxtSTqkkLYbnh4Ro2WhdwRjkfyBxBZZx8hfaM6MfLPi3A0rw9DPOSB4M/BMchtEh3bXuI7bue2tG+A==</InverseQ><D>ol/9qRjorEjF9XEjSr9rHddKxEGIST8RGeF+BNnCiTHkRziQdlykYIO876jzmsKhsG3STB+EZLsXM3ls9RZefcsPF5mLOCSOCow3DikfCtAy4hntsU9JwpuYE0V4A+Sgfd24fatqbu+JxE2nvpSbAPczDOgBFPNfYBkhMiuZ/iE=</D></RSAKeyValue>";
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
            RSA.FromXmlString(NET_PRIVATE_KEY);
            //要解密的密文
            //string pwv = @"c98qyUw0tWHzYuCpOY2X1pxMdtj5Sd11Xdrct+TS5fflMApfj+a2vXPnRSs6VDzdX+YSVVkV5cgd8/xINEtzBib8G8H/D669SgPNWdqOnIX+Xrebettbx7q9c7wcUYjFqC+6S+W58yDvR3y6S8FkGfbeBmCJcQHyw7Mmt0MSwXU=";
            //string pwv1 = @"fhTK2Z8meUzRm2NVEZlbH2Q6NDrIdOpgxdJ25FuqVOwlMo34z2dvsK2bo5a79u6vousPZJ1sEQ3MIJ/dVf7uiHhvBoxX9ortBGOp07gMk1zWynpagSPQwGFB99jZSegKYAQTijkrpw+WYwew+v8kHkK3RaoyrnUGk9waGjAez2g=";
            //解密
            byte[] pwb1 = Convert.FromBase64String(content);
            byte[] cpw1 = RSA.Decrypt(pwb1, false);
            string bc = Encoding.UTF8.GetString(cpw1);
            return bc;

        }


        /// <summary>
        /// RSA验签
        /// </summary>
        /// <param name="privatekey"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public string RSACheckKey(string account, string key)
        {
            string NET_PRIVATE_KEY = @"<RSAKeyValue><Modulus>vzPZCVcIvrDuu9jQZuXwBG1BJdj6kRbmGVQeWaymoe3iTz9KSgXv3qAOqTjLI5yhaGRlYs8+6ArfkyftX6bknJ+7wLSBUo59Y4DwDRPiHFXZOECgxSrtC0HYrqz0Ci6avEN8CQwFuxcQdjB8P+HGv/cNDeVS9IUHoGeGIcQ7LOk=</Modulus><Exponent>AQAB</Exponent><P>81Hqu5RXCBOLloURr3lRYzQBrkrFvqvRjsDu7UuWMLgCENjPl4GBkRaPMTAulf/Un6ibZklNc5O9qTJWLnyKhw==</P><Q>ySqkcKbWuobq5I9KSQISq2qCuGKtj/iUFho4PCD1YxhnQ7gcHA4OpS1dRFjtXJYQPTX9be+mmypsCFIyofE5Dw==</Q><DP>8ZnbTBqFOH2/0tuarfP2flx7dsbEBwmwcODd3T16ijGLy5KcvkFXl+sgj6TZ/RMj2syeUThj8Wk3n7Ndo5cCLQ==</DP><DQ>rNwKn46Nt4yVrT7/y0qPtmJ4325TzAIDZhazud9sXPGsUoGTDfx6Uy9vFHsBw+xjGeYZ1mz3EiBa4q+XOJbquw==</DQ><InverseQ>i90WdnZVPxtSTqkkLYbnh4Ro2WhdwRjkfyBxBZZx8hfaM6MfLPi3A0rw9DPOSB4M/BMchtEh3bXuI7bue2tG+A==</InverseQ><D>ol/9qRjorEjF9XEjSr9rHddKxEGIST8RGeF+BNnCiTHkRziQdlykYIO876jzmsKhsG3STB+EZLsXM3ls9RZefcsPF5mLOCSOCow3DikfCtAy4hntsU9JwpuYE0V4A+Sgfd24fatqbu+JxE2nvpSbAPczDOgBFPNfYBkhMiuZ/iE=</D></RSAKeyValue>";
            //string PUB_KEY_MODULES = @"<RSAKeyValue><Modulus>vzPZCVcIvrDuu9jQZuXwBG1BJdj6kRbmGVQeWaymoe3iTz9KSgXv3qAOqTjLI5yhaGRlYs8+6ArfkyftX6bknJ+7wLSBUo59Y4DwDRPiHFXZOECgxSrtC0HYrqz0Ci6avEN8CQwFuxcQdjB8P+HGv/cNDeVS9IUHoGeGIcQ7LOk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
            key = key.Replace("\\", "");
            key = key.Replace(\",  );
            key = key.Replace(" ", "");
            byte[] e = Encoding.UTF8.GetBytes(account);
            byte[] v = Convert.FromBase64String(key);
            RSA.FromXmlString(NET_PRIVATE_KEY);
            try
            {
                bool result4 = RSA.VerifyData(e, "MD5", v);
                if (result4)
                {
                    return "1";
                }
                else
                {
                    return "验签不通过!";
                }
            }
            catch
            {
                return "程序出错!";
            }
        }

 

以上是关于java如何实现各国时间格式转换成yyyy-MM-dd HH:mm:ss时间格式?的主要内容,如果未能解决你的问题,请参考以下文章

如何将“YYYYMM”格式转换为“YYYY-MM-00”?

java怎么将String转换成日期

在mysql中如何将时间的格式设置成yyyy-mm?

hive怎么把日期转化成yyyy-mm格式?

从日期时间列中提取 YYYY-MM

Java时间格式转换,如何获得时区?