当我实现DatePickerDialog时,它显示正确的日期,但是当我单击“确定”以在EditText中设置日期时,我得到的日期字符串带有不正确的月份,每次尝试时似乎都是随机的
USE [dbbib]
GO
/****** Object: StoredProcedure [dbo].[sp_QuerySummary] Script Date: 10/4/2018 4:13:57 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[sp_QuerySummary]
AS
BEGIN
DECLARE @columns VARCHAR(8000)
SELECT @columns = COALESCE(@columns + ',[' + cast(FailureMode as varchar) + ']',
'[' + cast(FailureMode as varchar)+ ']')
FROM (SELECT distinct FailureMode FROM tblBIB )as s
GROUP BY FailureMode
order by FailureMode
DECLARE @columns2 VARCHAR(8000)
SELECT @columns2 = COALESCE(@columns2 + ',isnull([' + cast(FailureMode as varchar) + '],0) as ['+ cast(FailureMode as varchar) +']',
'isnull([' + cast(FailureMode as varchar)+ '],0) as ['+ cast(FailureMode as varchar)+']')
FROM (SELECT distinct FailureMode FROM tblBIB )as s
GROUP BY FailureMode
order by FailureMode
DECLARE @columns3 VARCHAR(8000)
SELECT @columns3 = COALESCE(@columns3 + '+isnull([' + cast(FailureMode as varchar) + '],0)',
'isnull([' + cast(FailureMode as varchar)+ '],0)')
FROM (SELECT distinct FailureMode FROM tblBIB where FailureMode not like 'QUARANTINE' and FailureMode not like 'BARE' and FailureMode not like 'PM' and FailureMode not like 'TEMPORARY HOLD_SET B')as s
GROUP BY FailureMode
order by FailureMode
DECLARE @query VARCHAR(8000)
SET @query = '
declare @table table (BibType nvarchar(100), CntActive int)
insert into @table
select BibType,count(BibID) as CntActive from(
select substring(BibID,1,6) as BibType, BibID from(
select * ,
case
when len(BibID)>1 and len(BIBRecall)>1 then 1
when len(BibID)=1 and len(BIBRecall)>1 then 1
else 0
end as selection
from(
SELECT isnull(a.BibID,0) as BibID, isnull(tblBIB.BIBRecall,0)as BIBRecall
FROM (SELECT DISTINCT BibID
FROM Orca.dbo.tblLatestTurnAllBIB
WHERE (CONVERT(date, DTDone) = CONVERT(date, GETDATE()))) AS a full outer JOIN
tblBIB ON a.BibID = tblBIB.BIBRecall
)as s
)as s where selection=0
)as q group by BibType
declare @table2 table ( CntActive int, rn int)
insert into @table2
select count(BibID) as CntActive ,0 as rn from(
select substring(BibID,1,6) as BibType, BibID from(
select * ,
case
when len(BibID)>1 and len(BIBRecall)>1 then 1
when len(BibID)=1 and len(BIBRecall)>1 then 1
else 0
end as selection
from(
SELECT isnull(a.BibID,0) as BibID, isnull(tblBIB.BIBRecall,0)as BIBRecall
FROM (SELECT DISTINCT BibID
FROM Orca.dbo.tblLatestTurnAllBIB
WHERE (CONVERT(date, DTDone) = CONVERT(date, GETDATE()))) AS a full outer JOIN
tblBIB ON a.BibID = tblBIB.BIBRecall
)as s
)as s where selection=0
)as q
select*,row_number()over(order by total desc) as rn from(
SELECT Device,DeviceType,'+ @columns3 +' as Total,isnull(q.CntActive,0) as CntActive,'+ @columns2 +',q.BibType
FROM (SELECT a.DeviceType, tbldevtypev2.Device, a.Cnt, a.FailureMode
FROM (SELECT DeviceType, COUNT(BIBRecall) AS Cnt, FailureMode
FROM tblBIB
GROUP BY DeviceType, FailureMode) AS a left outer JOIN
tbldevtypev2 ON a.DeviceType = tbldevtypev2.[BIB Type]
)as a
PIVOT
(
MAX(Cnt)
FOR [FailureMode]
IN (' + @columns + ')
)
AS a left outer join @table q on a.DeviceType = q.BibType
)as p
union all
SELECT ''Grand Total'' as Device,'''' as DeviceType,'+@columns3+' as Total,*,'''' as BibType from(
Select isnull(i.CntActive,0) as CntActive,o.* from(
SELECT '+@columns2+',0 as rn
FROM (
SELECT COUNT(BIBRecall) AS Cnt, FailureMode
FROM tblBIB
GROUP BY FailureMode
)as a
PIVOT
(
MAX(Cnt)
FOR [FailureMode]
IN (' + @columns + ')
)
AS p
)as o full outer join @table2 i on o.rn= i.rn
)as p
'
EXECUTE(@query)
END
要显示DatePickerDialog,我有此功能
final Calendar calendar = Calendar.getInstance();
final DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
calendar.set(Calendar.YEAR,year);
calendar.set(Calendar.MONTH,month);
calendar.set(Calendar.DAY_OF_MONTH,dayOfMonth);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy", Locale.getDefault());
String newDate = dateFormat.format(new Date(calendar.getTimeInMillis()));
Log.e(TAG,"date: "+newDate);
mTextSetDate.setText(newDate);
}
};
}
这是日志输出
private void showDatePicker(DatePickerDialog.OnDateSetListener listener, Calendar cal){
new DatePickerDialog(AddNewRecordActivity.this,listener,
cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH)).show();
我包括了datepickerdialog和date string的一些屏幕截图