|
Thanks for that insight Gary.
|
|
|
|
|
Glad we finally got to the actual requirements
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|
2 monitors.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|
Our web server is on UTC. I want to display the server's current time on a web page, but converted to our office's local time, which is Central Time. Since UTC doesn't observe DST but our local time does, I can't just do
DateTime utcNow = DateTime.Now.AddHours(-6); since during DST it should be AddHours(-5).
Setting the server's time forward to May, I've tried using the following code to determine if the date as CTS is in DST:
DateTime utcNow = DateTime.UtcNow;
TimeZoneInfo csttzi = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
DateTime cstTime = TimeZoneInfo.ConvertTime(utcNow, csttzi);
Label1.Text = String.Format("IsDaylightSavingTime: {0}", cstTime.IsDaylightSavingTime().ToString()
But it returns False. Why? How can I determine if a time zone is currently in DST or not?
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
TNCaver wrote: But it returns False. Why?
Um ... because Daylight Savings Time doesn't start until the 12th March this year?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
He did say that he'd moved the server date to May.
This space for rent
|
|
|
|
|
I suspect it moved it back!
Try this:
DateTime then = new DateTime(2017, 6, 14, 8, 31, 45);
DateTime utcTime = then.ToUniversalTime();
TimeZoneInfo csttzi = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
DateTime cstTime = TimeZoneInfo.ConvertTime(utcTime, csttzi);
string text = String.Format("IsDaylightSavingTime: {0}", cstTime.IsDaylightSavingTime().ToString());
string officeTime = TimeZoneInfo.ConvertTime(utcTime, csttzi).ToString();
text is "IsDaylightSavingTime: True"
And officeTime is "14/06/2017 02:31:45"
Which is about right given I'm on GMT.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: I suspect it moved it back! It never did! I was looking at the server's clock the whole time, gov'na. Honest!
OriginalGriff wrote: Try this: Odd. Very odd. Your code gives me this:
IsDaylightSavingTime: False
Office Time: 6/14/2017 3:31:45 AM
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
As Gerry pointed out below, the DateTime.IsDaylightSavingTime method[^] relies on the local time zone. It has no knowledge of the TimeZoneInfo you used to change the offset.
If your server is set to UTC with no DST changes, then this method will never return true .
Use the TimeZoneInfo.IsDaylightSavingTime method[^] instead, and the result will depend on the chosen TimeZoneInfo .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I think your DST test plays off static TimeZoneInfo.Local; which always points to the host computer's time zone.
You can determine a "delta" hour for your "AddHours" though:
TimeZoneInfo.GetAdjustmentRules Method (System)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
You're probably right. It was showing Kind = Unspecified, so it wasn't obvious that this was the case.
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
How about:
Label1.Text = string.Format("IsDaylightSavingTime: {0}", csttzi.IsDaylightSavingTime(cstTime));
That will use the specified time zone, rather than the local system time zone.
You might also want to look at using DateTimeOffset[^], which is slightly better for time zone handling than a raw DateTime .
Or, if you want to be really safe, use Noda Time[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
There it is! That's what I was missing. I was thinking cstTime would carry that information, but I guess it doesn't.
Thank you!
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
I have created program that calculates day of week when entered date in format "January 7 2000" .Why do I get NullPointerException exception when I click button to calculate day of week?
Here is source code of app:
public class MainActivity extends AppCompatActivity
{
private int position;
private int value;
private Button button;
private EditText editText;
private TextView textView1,textView2;
private Spinner spinner,spinner2;
private ArrayAdapter<CharSequence> adapter;
private boolean isValid;
private Date date;
private int inMonth, inDay, inYear;
static boolean isDateValid(int month, int day, int year)
{
boolean validation = true;
int[] daysInMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (month < 1 || month > 12)
{
validation = false;
}
if (day < 1 || day > daysInMonth[month - 1])
{
validation = false;
}
if (year < 1700 || year > 3000)
{
validation = false;
}
return validation;
}
static String zellerCalc(int month, int day, int year)
{
String dayOfWeek;
int m = -1;
int h = -1;
int q = day;
int k;
int j;
if (month == 1)
{
m = 13;
}
else if (month == 2)
{
m = 14;
}
else
{
m = month;
}
if (m == 13 || m == 14)
{
year--;
}
k = year % 100;
j = year / 100;
h = (q + (int)((13 * (m + 1)) / 5.0) + k + (int)(k / 4.0) + (int)(j / 4.0) + (5 * j)) % 7;
if (h == 0)
{
dayOfWeek = "Subota";
}
else if (h == 1)
{
dayOfWeek = "Nedelja";
}
else if (h == 2)
{
dayOfWeek = "Ponedeljak";
}
else if (h == 3)
{
dayOfWeek = "Utorak";
}
else if (h == 4)
{
dayOfWeek = "Sreda";
}
else if (h == 5)
{
dayOfWeek = "Četvrtak";
}
else
dayOfWeek = "Petak";
return dayOfWeek;
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
button = (Button) findViewById(R.id.button_calculate);
textView1 = (TextView) findViewById(R.id.textView_day);
textView2 = (TextView) findViewById(R.id.textView_year);
spinner = (Spinner) findViewById(R.id.spinner_month);
spinner2 = (Spinner) findViewById(R.id.spinner_day);
editText = (EditText) findViewById(R.id.editText_year);
adapter = ArrayAdapter.createFromResource(this,R.array.months,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
adapter = ArrayAdapter.createFromResource(this,R.array.day,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter);
if (spinner2.getSelectedItemPosition() == 0)
value = 1;
if (spinner2.getSelectedItemPosition() == 1)
value = 2;
if (spinner2.getSelectedItemPosition() == 2)
value = 3;
if (spinner2.getSelectedItemPosition() == 3)
value = 4;
if (spinner2.getSelectedItemPosition() == 4)
value = 5;
if (spinner2.getSelectedItemPosition() == 5)
value = 6;
if (spinner2.getSelectedItemPosition() == 6)
value = 7;
if (spinner2.getSelectedItemPosition() == 7)
value = 8;
if (spinner2.getSelectedItemPosition() == 8)
value = 9;
if (spinner2.getSelectedItemPosition() == 9)
value = 10;
if (spinner2.getSelectedItemPosition() == 10)
value = 11;
if (spinner2.getSelectedItemPosition() == 11)
value = 12;
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
String dayOfWeek;
boolean isValid;
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String strDate = sdf.format(c.getTime());
do
{
try
{
String getdate = spinner.getItemAtPosition(position).toString() + value
+ textView2.getText().toString();
Date date = sdf.parse(getdate);
}
catch (ParseException ex)
{
}
isValid = isDateValid(date.getMonth(), date.getDay(), date.getYear());
if (isValid == false)
{
Toast.makeText(MainActivity.this,"You entered wrong date",Toast.LENGTH_SHORT).show();
}
}
while (isValid == false);
dayOfWeek = zellerCalc(date.getMonth(), date.getDay(), date.getYear());
textView1.setText(dayOfWeek);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
}
Logcat:
02-07 12:32:16.349 3049-3049/com.example.pavle.dayofborn E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.pavle.dayofborn, PID: 3049 java.lang.NullPointerException at com.example.pavle.dayofborn.MainActivity$2.onClick(MainActivity.java:230) at android.view.View.performClick(View.java:4633) at android.view.View$PerformClick.run(View.java:19270) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5476) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method)
//Line 230: isValid = isDateValid(date.getMonth(), date.getDay(), date.getYear());
|
|
|
|
|
Debug your code and find out why date is null. I can't help you any more than that. If this was C# like this forum is for, I might have been able to help more but this is not C# code.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
Pavlex4 wrote:
if (spinner2.getSelectedItemPosition() == 0)
value = 1;
if (spinner2.getSelectedItemPosition() == 1)
value = 2;
if (spinner2.getSelectedItemPosition() == 2)
value = 3;
if (spinner2.getSelectedItemPosition() == 3)
value = 4;
if (spinner2.getSelectedItemPosition() == 4)
value = 5;
if (spinner2.getSelectedItemPosition() == 5)
value = 6;
if (spinner2.getSelectedItemPosition() == 6)
value = 7;
if (spinner2.getSelectedItemPosition() == 7)
value = 8;
if (spinner2.getSelectedItemPosition() == 8)
value = 9;
if (spinner2.getSelectedItemPosition() == 9)
value = 10;
if (spinner2.getSelectedItemPosition() == 10)
value = 11;
if (spinner2.getSelectedItemPosition() == 11)
value = 12;
value = spinner2.getSelectedItemPosition() + 1;
Pavlex4 wrote: if (h == 0)
{
dayOfWeek = "Subota";
}
else if (h == 1)
{
dayOfWeek = "Nedelja";
}
else if (h == 2)
{
dayOfWeek = "Ponedeljak";
}
else if (h == 3)
{
dayOfWeek = "Utorak";
}
else if (h == 4)
{
dayOfWeek = "Sreda";
}
else if (h == 5)
{
dayOfWeek = "Četvrtak";
}
else
dayOfWeek = "Petak"; Please, put those in an array and fetch it by index.
Since the method is static, and assuming it does work like C#, I'd reckon that the 'date' variable is null. Which could happen if you were to swallow a parse-exception, for instance.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Ignoring for a moment that this is the C# forum, not the Android one.
if (spinner2.getSelectedItemPosition() == 0)
value = 1;
if (spinner2.getSelectedItemPosition() == 1)
value = 2;
Can you see any logic in all these if statements? Particularly that they could be replaced by the simple
value = spinner2.getSelectedItemPosition() + 1;
As to your actual problem, it is quite simple. You create a new Date variable inside your try block, but then try to use the one declared at class level to extract the various fields.
|
|
|
|
|
C#:
DayOfWeek dow = Convert.ToDateTime( "January 7 2000" ).DayOfWeek;
Time to find a new hobby.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
When loading items for PopupMenu if more items when PopupMenu load height not desirable, you want a fixed height instead PopupMenu anterior to PopupMenu then how ?
|
|
|
|
|
With no clue as to the UI you are using or the control suite help can only be generic.
Assuming your control does not have the attributes to define the size!
If your control supports sub menu items the reorganise you pop up menu.
If that is not possible you may need to change the control to a pop up window with a list control on command buttons.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I've read that transport security needs to be used in conjunction with SSL for improved security. I also read that SSL uses public key, private key, and a certificate to verify a website's identity.
What is not clear is whether SSL can encrypt WCF messages or not. If SSL can not encrypt WCF messages, then how do I encrypt the messages I'm trying to send?
|
|
|
|
|
SSL (or, more recently, TLS) encrypts all traffic between the client and server. WCF messages sent to an HTTPS endpoint will be encrypted.
Transport Layer Security - Wikipedia[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello,
Before coming to the problem statement, let me brief on the task I am working on.
I want to:
1. Add slide to a presentation
2. Insert video from external file to the slide, and then
3. Set PLAYBACK options of a video like Play Full Screen & Start Automatically.
So that, during the slide show, the video will be played fully before continuing to the next slide.
I could do tasks in point 1 & 2, but am stuck in point 3. I have referred MSDN documentation but too less information to accomplish my need.
Sharing snippet of code with appropriate comments:
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
.
.
.
PowerPoint.Application pptApp;
PowerPoint.Presentations oPresentations;
PowerPoint.Presentation oPresentation;
string sPath = @"C:\sample.avi";
pptApp = new PowerPoint.Application();
pptApp.Visible = MCore.MsoTriState.msoTrue;
oPresentations = pptApp.Presentations;
oPresentation = oPresentations.Add(MCore.MsoTriState.msoTrue);
PowerPoint.Slide slide = oPresentation.Slides.AddSlide(oPresentation.Slides.Count, oPresentation.Slides[oPresentation.Slides.Count].CustomLayout);
PowerPoint.Shape video = slide.Shapes.AddMediaObject2(sPath, MCore.MsoTriState.msoFalse, MCore.MsoTriState.msoTrue, 0f, 0f, -1f, -1f);
video.AnimationSettings.PlaySettings.PlayOnEntry = MCore.MsoTriState.msoTrue;
Kindly help me with this. Let me know if you need more information.
Thanks in advance.
-Shree
|
|
|
|
|