获得两个日期差,差的形式为:XX天XX小时XX分XX秒

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ycscsjj/article/details/84793195
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try

{

Date d1 = df.parse("2004-03-26 13:31:40");

Date d2 = df.parse("2004-01-02 11:30:24");
long diff = d1.getTime() - d2.getTime();//这样得到的差值是微秒级别
long days = diff / (1000 * 60 * 60 * 24);

long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
System.out.println(""+days+"天"+hours+"小时"+minutes+"分");

}
catch (Exception e)
{
}
展开阅读全文

无法将类型xx 隐式转换为xx

09-22

---WEB SERVER rnusing System;rnusing System.Web;rnusing System.Web.Services;rnusing System.Web.Services.Protocols;rnusing BaseLibrary;rnrn[WebService(Namespace = "http://tempuri.org/")]rn[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]rnpublic class EmployeeService : System.Web.Services.WebServicernrn rn public CredentialSoapHeader credential=new CredentialSoapHeader ();rn [WebMethod]rn [SoapHeader("credential", Direction = SoapHeaderDirection.In)]rn public string EmployeesSave(string strSQL)rn rnrn EmployeeLibrary el = new EmployeeLibrary();rn rn tryrn rn if (credential.Username == "12345" && credential.Password == "12345")rnrn return el.EmployeeSave(strSQL);rn elsern return null ;rn rn catch (SoapException Se)rn rn string strError = Se.Message.ToString();rn return null ;rn rnrn rn public class CredentialSoapHeader : SoapHeaderApplicationrn rn private string m_username;rn private string m_password;rn public override string Usernamern rn rn get return m_username; rnrn set m_username = value; rn rn rnrn public override string Passwordrn rn get return m_password; rnrn set m_password = value; rn rn rn rnrn*****************************rnClientrnrnusing System;rnusing System.Collections.Generic;rnusing System.Text;rnusing WebServiceTest.EmployeeService;rnusing WebServiceTest.BaseInfo;rnrnnamespace WebServiceTestrnrn class Controller:Credential rn rn public override string Usernamern rn getrn rn return "12345";rn rn setrn rn // throw new Exception("The method or operation is not implemented.");rn rn rnrn public override string Passwordrn rn getrn rn return "12345";rn rn setrn rn // throw new Exception("The method or operation is not implemented.");rn rn rn rn public class BBrn rn Controller UICredential = new Controller();rn public string BaseInfoSave(string strSQL)rn rn WebServiceTest.BaseInfo.BaseInfo bi = new WebServiceTest.BaseInfo.BaseInfo();rn tryrn rnrnrn bi.CredentialSoapHeaderValue = (WebServiceTest.BaseInfo.CredentialSoapHeader)UICredential;//这里出错rn return bi.Save("sss");rnrn rn catch (Exception ex)rn rn return (ex.Message.ToString());rn rn rn public string EmployeeServiceSave(string strSQL)rn rnrn WebServiceTest.EmployeeService.EmployeeService es = new WebServiceTest.EmployeeService.EmployeeService();rnrn tryrn rnrn es.CredentialSoapHeaderValue = (WebServiceTest.EmployeeService.CredentialSoapHeader)UICredential;//这里出错rn return es.EmployeesSave("xxxxx"); rnrn rn catch (Exception ex)rn rn return (ex.Message.ToString());rn rnrn rn rnrnrn 论坛

没有更多推荐了,返回首页