convert

How to convert std::chrono::time_point to calendar datetime string with fractional seconds?

匿名 (未验证) 提交于 2019-12-03 02:42:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to convert std::chrono::time_point to calendar datetime string with fractional seconds? For example: "10-10-2012 12:38:40.123456". 回答1: If system_clock, this class have time_t conversion. #include #include #include using namespace std::chrono; int main() { system_clock::time_point p = system_clock::now(); std::time_t t = system_clock::to_time_t(p); std::cout example result: Thu Oct 11 19:10:24 2012 EDIT: But, time_t does not contain fractional seconds. Alternative way is to use time_point::time_since_epoch() function. This function

How to convert a command line cUrl to PHP cUrl

匿名 (未验证) 提交于 2019-12-03 02:42:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I was trying to publish messages from PHP and I need to convert the following command into a PHP cURL: curl -X PUT --data-binary "Hello World" http://eclipse.mqttbridge.com/test No matter what I try i cannot get it going. I tried curl_exec and exec commands but no results. How do you convert this command into PHP cUrl, or at least execute from exec command? Thanks! 回答1: $data = "Hello World"; $ch = curl_init('http://eclipse.mqttbridge.com/test'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

Convert date to datetime in Python

匿名 (未验证) 提交于 2019-12-03 02:42:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Silly question, but is there a built-in method for converting a date to a datetime in Python, ie. getting the datetime for the midnight of the date ? The opposite conversion is easy - datetime has a .date() method. Do I really have to manually call datetime(d.year, d.month, d.day) ? 回答1: You can use datetime.combine (date, time); for the time, you create a datetime.time object initialized to midnight. from datetime import date from datetime import datetime d = date.today() datetime.combine(d, datetime.min.time()) 回答2: There are several ways,

Convert strings of list to list of integers inside a list

匿名 (未验证) 提交于 2019-12-03 02:41:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a list of strings and those strings are lists. Like this: ['[1,2,3]','[10,12,5]'] , for example. I want to get a list of lists or even every list there: [[1,2,3],[10,12,5]] 回答1: You should use literal_eval to get actual list object from string . >>> from ast import literal_eval >>> data = ['[1,2,3]','[10,12,5]'] >>> data = [literal_eval(each) for each in data] >>> data [[1, 2, 3], [10, 12, 5]] literal_eval safely evaluates each object. >>> help(literal_eval) Help on function literal_eval in module ast: literal_eval(node_or_string)

_beginthreadex cannot convert from 'overloaded-function'

匿名 (未验证) 提交于 2019-12-03 02:41:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I was making a function to print text layered across a different window, and I wanted it to be in a separate thread so I can run a timer for the text to display while leaving the user open to continue using the program. However, when I compile I get this error: error C2664: '_beginthreadex' : cannot convert parameter 3 from 'overloaded-function' to 'unsigned int (__stdcall *)(void *)' Here's the main cpp file: #include "stdafx.h" #include "Trial.h" int main() { wchar_t* text = L"Message!"; HWND hwnd = FindWindowW(0, L"Halo"); unsigned

How to convert a Carbon AXUIElementRef to Cocoa NSWindow

匿名 (未验证) 提交于 2019-12-03 02:40:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my project, i can get the window which mouse is on, and i can use AXUIElementSetAttributeValue(element, kAXFrontmostAttribute, kCFBooleanTrue); to make the window to top level temporarily. So i want to convert the element to Cocoa NSWindow and then use makeKeyAndOrderFront to make it always in front. Anyone know how to implement this. + (NSArray *)attributeNamesOfUIElement:(AXUIElementRef)element { NSArray *attrNames = nil; AXUIElementCopyAttributeNames(element, (const void*)&attrNames); AXUIElementSetAttributeValue(element,

C# Base64 String to JPEG Image

匿名 (未验证) 提交于 2019-12-03 02:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to convert a Base64String to an image which needs to be saved locally. At the moment, my code is able to save the image but when I open the saved image, it says "Invalid Image". Code: try { using (var imageFile = new StreamWriter(filePath)) { imageFile.Write(resizeImage.Content); imageFile.Close(); } } The Content is a string object which contains the Base64 String. 回答1: So with the code you have provided. var bytes = Convert.FromBase64String(resizeImage.Content); using (var imageFile = new FileStream(filePath, FileMode.Create))

How to convert a long form table to wide form table in Excel?

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: A picture is worth a thousand words. Let's say in one sheet I have the following table: Using this information, I want to programatically generate the table like this(sort of un-melting the long table into the wide form) in another sheet: How can you achieve this? 回答1: Using VBA: Range("G1:K99").Clear For Each xx In Range("A:A") If xx.Value = "" Then Exit Sub Range("G1").Offset(xx.Value, 0) = xx.Value For e = 1 To 99 If Range("G1").Offset(xx.Value, e) = "" Then Range("G1").Offset(xx.Value, e) = xx.Offset(0, 1).Value Exit For End If Next Next

Convert string to list. Python [string.split() acting weird]

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: temp = "['a','b','c']" print type(temp) #string output = ['a','b','c'] print type(output) #list so i have this temporary string which is basically a list in string format . . . i'm trying to turn it back into a list but i'm not sure a simple way to do it . i know one way but i'd rather not use regex if i use temp.split() I get temp_2 = ["['a','b','c']"] 回答1: Use ast.literal_eval() : Safely evaluate an expression node or a Unicode or Latin-1 encoded string containing a Python expression. The string or node provided may only consist of the

C# Base64 String to JPEG Image

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to convert a Base64String to an image which needs to be saved locally. At the moment, my code is able to save the image but when I open the saved image, it says "Invalid Image". Code: try { using (var imageFile = new StreamWriter(filePath)) { imageFile.Write(resizeImage.Content); imageFile.Close(); } } The Content is a string object which contains the Base64 String. 回答1: So with the code you have provided. var bytes = Convert.FromBase64String(resizeImage.Content); using (var imageFile = new FileStream(filePath, FileMode.Create))