Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
DateTimeOffset.Now = {2/22/2018 10:32:50 AM -06:00} been converted to
xmlformatTime = "2018-02-22T10:33:18.2670639-06:00", , in the format need to remove and expected o/p as 2018-02-22T10:33:18.00-06:00.
18.2670639 needs to change as 18.00
DateTimeOffset PassDate = DateTimeOffset.Now;
int minutes = PassDate.Minute;
int seconds = PassDate.Second;
var offset = PassDate.Offset;
var xmlformatTime = PassDate.ToString("o");
Console.WriteLine(xmlformatTime)
when tried with below option.
var xmlformatTime = PassDate.ToString("'MM'-'dd'T'HH':'mm':'ss'.00'K");
From MSDN:
The "O" or "o" standard format specifier corresponds to the "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffzzz" custom format string for DateTimeOffset values
So use
var xmlformatTime = PassDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.00'zzz");
instead to change the milliseconds to zeros.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How to check a string is combined by year and week number by c# code?
Like "202153",here "53" is the 53th week in 2021,and the week number cannot over 53 in 2021,
so,"202154" is not valid.
Thanks everyone for your suggestions, this is indeed an ambiguous question.I confirmed with my leader that our current system only needs to consider that the number of weeks does not exceed 53.
try this. you can change last line as per logic.
string date1 = "202154";
int year = Convert.ToInt32(date1.Substring(0, 4));
int weekNo = Convert.ToInt32(date1.Substring(4, 2));
//Validate week
DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
DateTime date = new DateTime(year, 12, 31);//Get last date of year
Calendar cal = dfi.Calendar;
int weekOfYear = cal.GetWeekOfYear(date, dfi.CalendarWeekRule, dfi.FirstDayOfWeek);//Get last week of the year.
bool answer = weekNo > weekOfYear?false:true;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to get report between 2 dates with PersianCalendar and I've already converted the dates. It does not show me the data about last day
This is my code:
public ActionResult FilterDate(DateFormViewModel model)
{
PersianCalendar pc = new PersianCalendar();
var dateFrom = pc.ToDateTime(model.FromYear, model.FromMonth, model.FromDay, 0, 0, 0, 0);
var dateTo = pc.ToDateTime(model.ToYear, model.ToMonth, model.ToDay, 0, 0, 0, 0);
var filter = db.Parts.Where(s => s.CreateDateTime >= dateFrom && s.CreateDateTime <= dateTo).ToList();
return View("Index", filter);
}
You're searching from midnight of the start date to 12 AM of the end date. You want to search from midnight of the start date to 11:59:59 PM of the end date.
You are missing data on the last day, right? (15 mordad)
The reason is that you are looking to the same day. having <= in the query does not help you.
for instance 1395/5/15 01:00:00 is greater than 1395/5/15 (your dateTo) and therefore it will not show up in the results
you have to check it with next day
var filter = db.Parts.Where(s => s.CreateDateTime >= dateFrom && s.CreateDateTime < dateTo.AddDay(1)).ToList();
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How to covert DateTime to int
DateTime now = DateTime.Now;
int va = now.Year;
// error here
int vd = int.Parse(mYear.Value.ToShortDateString());
result = Convert.ToString(va - vd);
Input string was not in a correct format
Assuming mYear is of Type DateTime - Just do it like you did with now:
int vd = mYear.Year;
If it's a string like "2014", use something like:
DateTime.ParseExact(mYear, "yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);
Not sure what Parse is going to do with escape chars.
// The example displays the following output:
// Displaying short date for en-US culture:
// 6/1/2009 (Short Date String)
// 6/1/2009 ('d' standard format specifier)
# ElGavilan commented to the same effect while I was posting.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Computers in my country do not accept decimals with a '.' they only accept ','
How do I write a program which would accept 12.5 from the console as a decimal number?
Use CultureInfo. If you are sure that using decimal dot is a standard in your country then use your country's CultureInfo. You can simply check if it is.
// Change kk-KZ to your culture code
decimal dec = decimal.Parse(str, new CultureInfo("kk-KZ"));
Or you can use InvariantCulture and NumberStyles.Any:
decimal dec = decimal.Parse(str, NumberStyles.Any, CultureInfo.InvariantCulture);
I will implement the second one as I don't know where you are from.
Here it is in an console application and it works for me:
public static void Main()
{
string str;
str = Console.ReadLine();
decimal dec = decimal.Parse(str, NumberStyles.Any, CultureInfo.InvariantCulture);
double db = double.Parse(str, NumberStyles.Any, CultureInfo.InvariantCulture);
Console.WriteLine(dec.ToString("F2", CultureInfo.InvariantCulture));
Console.WriteLine(db.ToString("F2", CultureInfo.InvariantCulture));
return;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
addition of two month and year in asp.net with c#.
if i select any one Month/year: like march/2014 and add(+) 12 month,
so it should be give the February/2014.
In this we can see Loan Period is: 12 (month) and below we can see loan start from month: 07(july/2014) so end of the load should be 06/2015. and the both month are in textbox it means they are string.
DateTime dt = new DateTime(2013, 1, 1);
dt.AddYear(1);
dt.AddMonths(2);
//Date is 2014, 3 (March), 1
Alternatively if you wish to substrat years and months you can use:
dt.AddYear(-1);
dt.AddMonths(-1);
//Date is 2013, 2 (February),1
Here you will not get 02/2015 if you add 12 months in 03/2014. You will get 03/2015 in result as shown below.
var inputString = "march/2014";
DateTime dt = DateTime.ParseExact(inputString, "MMMM/yyyy", CultureInfo.InvariantCulture);
var result = dt.AddMonths(12).ToString("MMMM/yyyy");
Will result in => "march/2015"
It seems that yous should add -1, not 12 months (if you want to get February from March):
String fromDate = "march/2013";
// result == "February/2013"
String result = DateTime
.ParseExact(fromDate, "MMMM/yyyy", CultureInfo.InvariantCulture)
.AddMonths(-1)
.ToString("MMMM/yyyy", CultureInfo.InvariantCulture);
In case that you want to add a year and two months (and so your example is incorrect)
String fromDate = "march/2013";
// result == "May/2014"
String result = DateTime
.ParseExact(fromDate, "MMMM/yyyy", CultureInfo.InvariantCulture)
.AddYears(1)
.AddMonths(2)
.ToString("MMMM/yyyy", CultureInfo.InvariantCulture);