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 2 years ago.
Improve this question
I am not a C# programmer, but was given an API where part of their code requires generating of a Timestamp but example was given in C# so I am stuck as to how I can get the same results in PHP. Can someone here help to show me how this code would be in Php?
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
DateTime dtNow = DateTime.Parse(DateTime.Now.ToString());
TimeSpan toNow = dtNow.Subtract(dtStart);
string timeStamp = toNow.Ticks.ToString().Substring(0, timeStamp.Length - 7);
I am sort of able to get the first 2 line into PHP, but 3rd line onwards, I am lost.
<?php
$date = new DateTime(); // OR new DateTime('2000-01-01');
$timestamp = $date->getTimestamp();
?>
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 5 years ago.
Improve this question
I m very new to C# and have some issue. I've a project where I need to change the date when School starts at 0700 am only not at 1200 am. I tried something like this but doesn't work
System.TimeSpan timeDiff = TimeSpan.FromHours(.292);
DateTime presentDate = (Convert.ToDateTime(sysDateTime)).Subtract(timeDiff);
I used this way in VB6 where I just substract .292 from current dateTime to change the date at 0700 am instead of 1200 am but dont know how do I achieve the same in C#.
You can try with
DateTime d = (Convert.ToDateTime(sysDateTime)).Subtract(new TimeSpan(5, 0, 0));
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have .CSV file and there is Date column but it has content date and time like follows;
24/02/2017 13:57:53
manageInstance.Date = DateTime.ParseExact(valuesInCsvLine[0], dateFormatString, CultureInfo.InvariantCulture);
So,how I get time only from this format.I am doing C# programming.If anyone know,please help me.I am newer to this language.
You can parse your String as DateTime like
var text = "24/02/2017 13:57:53";
var dateTime = DateTime.Parse(text);
And then you can access the time like
var time = dateTime.TimeOfDay;
You can get time like var timeOnly = DateTime.Now.TimeOfDay;.
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 have decimal values in the database. I want to show the decimal value in it. How to convert decimal values into it.
int vatprice;
dt.Load(cmd.ExecuteReader());
vatprice = Convert.ToInt32(dt.Rows[0][5].ToString());//getting error here
As per your requirement, round decimal up to 2 place using following way :
1) Use Math.Round().
var vatprice= Convert.ToDecimal(Math.Round(dt.Rows[0][5], 2));
2) second way is
var vatprice=Convert.ToDecimal(dt.Rows[0][5].ToString ("#.##"));
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 9 years ago.
Improve this question
How do I convert this the time the computer has been to sleep for (here called 'offTime') into an integer (in terms of minutes)?
`DateTime timeOnSleep = DateTime.Now;`
`Application.SetSuspendState(PowerState.Suspend, true, true);`
`DateTime timeOnWake = DateTime.Now;`
`System.TimeSpan offTime = timeOnWake - timeOnSleep;`
TimeSpan time = timeOnWake - timeOnSleep;
var hours = time.TotalHours;
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
I have a string "5-13-2013"
I want to make it look like "051313"
All three fields (month,day,year) must have 2 digits, if it only has one , I need to add a zero in front
any easy way to do this?
You can convert your datetime to multiple formats like
string date = yourdateTime.ToString("dd/mm/yyyy");
string date = yourdateTime.ToString("dd/mm/yyyy HH:mm");
string date = yourdateTime.ToString("dd/mm/yyyy HH:mm:ss");
string date = yourdateTime.ToString("mmddyy"); // your desired
To know what these mean you need to read here.